From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297023; cv=none; d=zohomail.com; s=zohoarc; b=LOjQqyns1hRHxeCe3/D3WId0sRATHIRJLR/GgopYOEMoqz3Q0Ul9csnBcn0sJRpPGogyxrkAbk9IMtHQt6K4TXpfBZZo8Jh1oKfJIzJeTHEFte4qGsxic9ayS684oI6lvw7uXctGlseSXDO6h0aSEh84OPLVK+ZGpPTheYB7pek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297023; 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=HGdILztNMy0HHXpr+S6Sh0/Ub6zEA2jd2NIP03tM6/w=; b=nryvsRStbBneIsaRE/tkBpDcklOOhGFgSqFaxgZQCeLbPYcjD5EiMLATWhkvGHj63+Me11sRhUCcWyiwJbqOXrTtOJ3UulW1QJQZuT3V73Emx3YNGwKK8oEb9qFddwQkKkCimGml4nj2LVFr1t7lU8RnoArVu5b9x4BDHKfehdk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297023616324.18993889837066; Tue, 13 Jan 2026 01:37:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfapc-000679-8R; Tue, 13 Jan 2026 04:36:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapZ-00060f-DN for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:36:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapX-0003Fq-Aw for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:36:53 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-144-lxVvW5Z-Pee1VNWsN1Wisg-1; Tue, 13 Jan 2026 04:36:45 -0500 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0EDCE1800447; Tue, 13 Jan 2026 09:36:44 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 18BE530001A2; Tue, 13 Jan 2026 09:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297010; 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=HGdILztNMy0HHXpr+S6Sh0/Ub6zEA2jd2NIP03tM6/w=; b=ZpGCRBphuLVL8/EwwtnI0rr9xJ22lZq5ctBpXQdRbwgIS7dLEwpWdUAPXIqwLst+wxKieK ugk/nOsuei9GX9cx8J5GN49n2YSVOfwJtFwj0WteQf6ESmOb0tDpjLXkLZMk7cJV8fr441 r0n3kCEXLBfRtgBrKaJVhTw35gvYpF0= X-MC-Unique: lxVvW5Z-Pee1VNWsN1Wisg-1 X-Mimecast-MFC-AGG-ID: lxVvW5Z-Pee1VNWsN1Wisg_1768297004 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Maciej S. Szmigiero" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 01/41] hw/vfio/migration: Check base architecture at runtime Date: Tue, 13 Jan 2026 10:35:57 +0100 Message-ID: <20260113093637.1549214-2-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297025324158500 From: Philippe Mathieu-Daud=C3=A9 Inline vfio_arch_wants_loading_config_after_iter() and replace the compile time check of the TARGET_ARM definition by a runtime call to target_base_arm(). Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Maciej S. Szmigiero Link: https://lore.kernel.org/qemu-devel/20251021161707.8324-1-philmd@linar= o.org Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-helpers.h | 2 -- hw/vfio/helpers.c | 17 ----------------- hw/vfio/migration-multifd.c | 12 +++++++++++- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/hw/vfio/vfio-helpers.h b/hw/vfio/vfio-helpers.h index ce317580800ac0c96696e8d3769a98c21d2716d0..54a327ffbc04a2df364fdd78bd9= 7fe7e2065b38c 100644 --- a/hw/vfio/vfio-helpers.h +++ b/hw/vfio/vfio-helpers.h @@ -32,6 +32,4 @@ struct vfio_device_info *vfio_get_device_info(int fd); int vfio_kvm_device_add_fd(int fd, Error **errp); int vfio_kvm_device_del_fd(int fd, Error **errp); =20 -bool vfio_arch_wants_loading_config_after_iter(void); - #endif /* HW_VFIO_VFIO_HELPERS_H */ diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index c595f860cea91398bffce515e8d25bd462c1a20b..f68f8165d091abd7faac778d8c9= 0da27a8f5f5f8 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -210,20 +210,3 @@ retry: =20 return info; } - -bool vfio_arch_wants_loading_config_after_iter(void) -{ - /* - * Starting the config load only after all iterables were loaded (duri= ng - * non-iterables loading phase) is required for ARM64 due to this plat= form - * VFIO dependency on interrupt controller being loaded first. - * - * See commit d329f5032e17 ("vfio: Move the saving of the config space= to - * the right place in VFIO migration"). - */ -#if defined(TARGET_ARM) - return true; -#else - return false; -#endif -} diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c index 4a855f4e1257fd0094d720a1dd0fd2aa25acb25f..a06cbf3c646896d7f87698b0d65= 4b160be995237 100644 --- a/hw/vfio/migration-multifd.c +++ b/hw/vfio/migration-multifd.c @@ -16,6 +16,7 @@ #include "qemu/error-report.h" #include "qemu/lockable.h" #include "qemu/main-loop.h" +#include "qemu/target-info.h" #include "qemu/thread.h" #include "io/channel-buffer.h" #include "migration/qemu-file.h" @@ -44,7 +45,16 @@ bool vfio_load_config_after_iter(VFIODevice *vbasedev) } =20 assert(vbasedev->migration_load_config_after_iter =3D=3D ON_OFF_AUTO_A= UTO); - return vfio_arch_wants_loading_config_after_iter(); + + /* + * Starting the config load only after all iterables were loaded (duri= ng + * non-iterables loading phase) is required for ARM64 due to this plat= form + * VFIO dependency on interrupt controller being loaded first. + * + * See commit d329f5032e17 ("vfio: Move the saving of the config space= to + * the right place in VFIO migration"). + */ + return target_base_arm(); } =20 /* type safety */ --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297023; cv=none; d=zohomail.com; s=zohoarc; b=TMEm4BeBbzFuk1j9tNROIdITdYiswUEeta18wp/BHw4LtFCmeWvXA+JwBLVjwItuhr9TVS6XGfrIdNP9GnmVumqI0VAXJZe7NRBSfeNqFv2KkMhHI9aNcYE3hPZjTalH2uZj/VH8fZdg01FY3WeN5XTqoHsbJrs+kzB8U/SqZyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297023; 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=70XX6/lwyq36rjgmSKCR1ZXI8qD3s28GlFWvTUH7Uf0=; b=mgFDzJhUCXf7O/sjw/ApjnqnGDzvTs6eyzZt17KTMPYfKy5VZgA0qVnvZtdyqRLrLBM9UNxm4/r4RrbDgf+l6eMQDCJke4P1iai/us0++r6/v6tGkl1r+e1hq5g0Xm1iwgjySDM0PUNsYwiG7LzHKcmUS1Ob4n8epDzFeu9frFQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297023835289.3846458675208; Tue, 13 Jan 2026 01:37:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfape-0006BZ-Of; Tue, 13 Jan 2026 04:36:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapa-00065W-Cv for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:36:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapX-0003Fs-QY for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:36:53 -0500 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-436-mBYB2fT8MzWM0wnnHMVKsw-1; Tue, 13 Jan 2026 04:36:47 -0500 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 7C3581955D93; Tue, 13 Jan 2026 09:36:46 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 99B6F30001A2; Tue, 13 Jan 2026 09:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297010; 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=70XX6/lwyq36rjgmSKCR1ZXI8qD3s28GlFWvTUH7Uf0=; b=dqRVgcKdTeTaOdI0sU2kZtQN95nfA681MBQ9Sv867ZkJFw2o09GyK+jN7ZSVAIGRItku7c ZEiyeqN7ZWCdGLqmf4WzvMfpzhGKixFIi2CS8KUcWnMpoD/X52Xpl0vAegfu4DlN61vuVm 891Gjv7+S7WkbJtaF65RGZV4IAd0oZM= X-MC-Unique: mBYB2fT8MzWM0wnnHMVKsw-1 X-Mimecast-MFC-AGG-ID: mBYB2fT8MzWM0wnnHMVKsw_1768297006 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 02/41] docs/devel: Remove stale comments related to iommufd dirty tracking Date: Tue, 13 Jan 2026 10:35:58 +0100 Message-ID: <20260113093637.1549214-3-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297025280158500 From: Zhenzhong Duan IOMMUFD dirty tracking support had be merged in merge commit dd4bc5f1cfe9, the stale comments could be dropped. Signed-off-by: Zhenzhong Duan Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20251226073007.1139478-1-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- docs/devel/vfio-iommufd.rst | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/docs/devel/vfio-iommufd.rst b/docs/devel/vfio-iommufd.rst index 3d1c11f175e5968e9f1519da70c9a0a6ced03995..b37098e1b625d9be0368e53b749= 2db64828c88c3 100644 --- a/docs/devel/vfio-iommufd.rst +++ b/docs/devel/vfio-iommufd.rst @@ -127,18 +127,6 @@ Supports x86, ARM and s390x currently. Caveats =3D=3D=3D=3D=3D=3D=3D =20 -Dirty page sync ---------------- - -Dirty page sync with iommufd backend is unsupported yet, live migration is -disabled by default. But it can be force enabled like below, low efficient -though. - -.. code-block:: bash - - -object iommufd,id=3Diommufd0 - -device vfio-pci,host=3D0000:02:00.0,iommufd=3Diommufd0,enable-migrati= on=3Don - P2P DMA ------- =20 --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297041; cv=none; d=zohomail.com; s=zohoarc; b=e6KXPiJ8lDlughKKNRoeCMKfL93RvA+QF76H5mmGMbaZaU3OFoOLNeI3kMN29up2NwzC1ZbOJzt/DEv15VdnQeidSC0iJL8MhQbwxj+A9DDzJTQoLxTRux930QdORUc1giur13z1tQ+fv1HnnnhyP2ZG5Xyctd7Dd+IIqdWmKik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297041; 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=WINxKjiuW6IF/tyBCdsyzHb1uNn8zxXjM9EpMOvrtTg=; b=RXwsh2ijoXVern2nbuMEWb9E+Mlbht05U6qrbTexXHxp4WdIAWj8rekKyQVqs2DONgzKyrrB2EaTM3kT0OTVtyqP5eSonBL+Md3nECtT6dZbIAE2dOwFsgUKCoIchpfJwEC/deSDNg5RvXX/OXy7r2qzcrRfWCjh0YZ603K1fc4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297041609488.9857352498284; Tue, 13 Jan 2026 01:37:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfapf-0006Ew-Kx; Tue, 13 Jan 2026 04:36:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapc-00069O-Ow for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:36:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapb-0003GK-1U for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:36:56 -0500 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-390-7qlxOg2eMOmDXgEKpQMMRA-1; Tue, 13 Jan 2026 04:36:52 -0500 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 63EFF19560A5; Tue, 13 Jan 2026 09:36:50 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EE8F630001A8; Tue, 13 Jan 2026 09:36:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297014; 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=WINxKjiuW6IF/tyBCdsyzHb1uNn8zxXjM9EpMOvrtTg=; b=K6ozQrFPebIS9oT0UwS6e6zdOlue50HfYcqLAzFOqoJ/J3L8nUfuiMvJDVyGfk36LICIIL Oy9VKXBoMkr3PpQRmncwGLUU7/JmD8ukBZeBUDd2u8EqTdcJUJsDE/36wgYuSHItByvXgL NG50hIt0Gq1JGTnRXmAF41pFFR7yzhI= X-MC-Unique: 7qlxOg2eMOmDXgEKpQMMRA-1 X-Mimecast-MFC-AGG-ID: 7qlxOg2eMOmDXgEKpQMMRA_1768297010 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?Cl=C3=A9ment=20Mathieu--Drif?= , Yi Liu , Eric Auger , Nicolin Chen , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 03/41] intel_iommu: Rename vtd_ce_get_rid2pasid_entry to vtd_ce_get_pasid_entry Date: Tue, 13 Jan 2026 10:35:59 +0100 Message-ID: <20260113093637.1549214-4-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297043878158500 From: Zhenzhong Duan In early days vtd_ce_get_rid2pasid_entry() was used to get pasid entry of rid2pasid, then it was extended to get any pasid entry. So a new name vtd_ce_get_pasid_entry is better to match what it actually does. No functional change intended. Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif Reviewed-by: Yi Liu Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-2-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 224b7b947906589c49c26bf4f7cd1ff81a46bd1f..436a30288b7b79e0d886447ddf7= eddab489f2e63 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -954,10 +954,8 @@ static int vtd_get_pe_from_pasid_table(IntelIOMMUState= *s, return 0; } =20 -static int vtd_ce_get_rid2pasid_entry(IntelIOMMUState *s, - VTDContextEntry *ce, - VTDPASIDEntry *pe, - uint32_t pasid) +static int vtd_ce_get_pasid_entry(IntelIOMMUState *s, VTDContextEntry *ce, + VTDPASIDEntry *pe, uint32_t pasid) { dma_addr_t pasid_dir_base; int ret =3D 0; @@ -1035,7 +1033,7 @@ static uint32_t vtd_get_iova_level(IntelIOMMUState *s, VTDPASIDEntry pe; =20 if (s->root_scalable) { - vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); + vtd_ce_get_pasid_entry(s, ce, &pe, pasid); if (s->flts) { return VTD_PE_GET_FL_LEVEL(&pe); } else { @@ -1058,7 +1056,7 @@ static uint32_t vtd_get_iova_agaw(IntelIOMMUState *s, VTDPASIDEntry pe; =20 if (s->root_scalable) { - vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); + vtd_ce_get_pasid_entry(s, ce, &pe, pasid); return 30 + ((pe.val[0] >> 2) & VTD_SM_PASID_ENTRY_AW) * 9; } =20 @@ -1126,7 +1124,7 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUS= tate *s, VTDPASIDEntry pe; =20 if (s->root_scalable) { - vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); + vtd_ce_get_pasid_entry(s, ce, &pe, pasid); if (s->flts) { return pe.val[2] & VTD_SM_PASID_ENTRY_FLPTPTR; } else { @@ -1532,7 +1530,7 @@ static int vtd_ce_rid2pasid_check(IntelIOMMUState *s, * has valid rid2pasid setting, which includes valid * rid2pasid field and corresponding pasid entry setting */ - return vtd_ce_get_rid2pasid_entry(s, ce, &pe, PCI_NO_PASID); + return vtd_ce_get_pasid_entry(s, ce, &pe, PCI_NO_PASID); } =20 /* Map a device to its corresponding domain (context-entry) */ @@ -1621,7 +1619,7 @@ static uint16_t vtd_get_domain_id(IntelIOMMUState *s, VTDPASIDEntry pe; =20 if (s->root_scalable) { - vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); + vtd_ce_get_pasid_entry(s, ce, &pe, pasid); return VTD_SM_PASID_ENTRY_DID(pe.val[1]); } =20 @@ -1697,7 +1695,7 @@ static bool vtd_dev_pt_enabled(IntelIOMMUState *s, VT= DContextEntry *ce, int ret; =20 if (s->root_scalable) { - ret =3D vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); + ret =3D vtd_ce_get_pasid_entry(s, ce, &pe, pasid); if (ret) { /* * This error is guest triggerable. We should assumt PT @@ -3083,7 +3081,7 @@ static inline int vtd_dev_get_pe_from_pasid(VTDAddres= sSpace *vtd_as, return ret; } =20 - return vtd_ce_get_rid2pasid_entry(s, &ce, pe, vtd_as->pasid); + return vtd_ce_get_pasid_entry(s, &ce, pe, vtd_as->pasid); } =20 static int vtd_pasid_entry_compare(VTDPASIDEntry *p1, VTDPASIDEntry *p2) @@ -5161,7 +5159,7 @@ static int vtd_pri_perform_implicit_invalidation(VTDA= ddressSpace *vtd_as, if (ret) { return -EINVAL; } - ret =3D vtd_ce_get_rid2pasid_entry(s, &ce, &pe, vtd_as->pasid); + ret =3D vtd_ce_get_pasid_entry(s, &ce, &pe, vtd_as->pasid); if (ret) { return -EINVAL; } --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297037; cv=none; d=zohomail.com; s=zohoarc; b=YwOA0ZQhN4X4jKTRfi7N+NZrAJ2Doj+i1Whg8LDjVNJYuBoOR9kjYpHj+pYNTeBNzL90ve4QYOzIg1EnwK3MumexB7KEvSYb2Ux3v6XwzB0JwWdbhpWKppC1fu6VBxuVoo8rhxEoTnj2WM3CUq/BXdXFemPAAOZaY5+BR2nCfvg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297037; 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=HhaoZh7qcv3Y69IN8LKpRllqRNpal1FHLT/cDourskM=; b=dbXS0mZbgfYgEEn+DYLsoIDvl7k+Cye1sHVSirsL//Pug6AZyC9647HSnRq/DGUDxs3coUyy4CgsxQ2CxshV2qHkMK7W/Ni+ujWq0PGNFPTcjTFNsN/OQ2yXfcW86B/1bYazruhSExM2zqrO8rOcuBL64wS0Zr9/lTNaxzXx5YM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297037110519.5512299888271; Tue, 13 Jan 2026 01:37:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfapi-0006RU-6X; Tue, 13 Jan 2026 04:37:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapg-0006GE-09 for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfape-0003GV-0v for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:36:59 -0500 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-500-qgoY8Eh2PF2HmoOh_JOnkw-1; Tue, 13 Jan 2026 04:36:54 -0500 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 0E7A61955F34; Tue, 13 Jan 2026 09:36:53 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D317530001A2; Tue, 13 Jan 2026 09:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297017; 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=HhaoZh7qcv3Y69IN8LKpRllqRNpal1FHLT/cDourskM=; b=F7Gmsw4ASI0EMdBQ1rdDRbgOhxVSl3OlvZ6ngwdLOskZcQx4swSuJTc2X8ud8XE4AMLqLu v79OtaqzUGVEWgG7JqLS+0xC6Uz7NQ+vwBhVsL7yo6UQcsKMzwZ5UwLrFqE3/DZ3lre1AF NGpNe+H+FY97Val7v5UYRYRpSvriu1Q= X-MC-Unique: qgoY8Eh2PF2HmoOh_JOnkw-1 X-Mimecast-MFC-AGG-ID: qgoY8Eh2PF2HmoOh_JOnkw_1768297013 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , Eric Auger , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 04/41] intel_iommu: Delete RPS capability related supporting code Date: Tue, 13 Jan 2026 10:36:00 +0100 Message-ID: <20260113093637.1549214-5-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297037566158500 From: Zhenzhong Duan RID-PASID Support(RPS) is not set in vIOMMU ECAP register, the supporting code is there but never takes effect. Meanwhile, according to VTD spec section 3.4.3: "Implementations not supporting RID_PASID capability (ECAP_REG.RPS is 0b), use a PASID value of 0 to perform address translation for requests without PASID." We should delete the supporting code which fetches RID_PASID field from scalable context entry and use 0 as RID_PASID directly, because RID_PASID field is ignored if no RPS support according to spec. This simplifies the code and doesn't bring any penalty. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-3-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_internal.h | 2 +- hw/i386/intel_iommu.c | 89 +++++++++++----------------------- 2 files changed, 28 insertions(+), 63 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 75bafdf0cde663e06a2fba0cd0cf80188c461d4c..36d04427dd7a8c0e8ebe6ebc3c5= f742eefa7ce9b 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -609,7 +609,7 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_CTX_ENTRY_LEGACY_SIZE 16 #define VTD_CTX_ENTRY_SCALABLE_SIZE 32 =20 -#define VTD_SM_CONTEXT_ENTRY_RID2PASID_MASK 0xfffff +#define PASID_0 0 #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL0(aw) (0x1e0ULL | ~VTD_HAW_MASK(aw)) #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL1 0xffffffffffe00000ULL #define VTD_SM_CONTEXT_ENTRY_PRE 0x10ULL diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 436a30288b7b79e0d886447ddf7eddab489f2e63..2d3673db3737ce1ad7dbd5ccfd0= 6019ae1782ce0 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -41,8 +41,6 @@ #include "trace.h" =20 /* context entry operations */ -#define VTD_CE_GET_RID2PASID(ce) \ - ((ce)->val[1] & VTD_SM_CONTEXT_ENTRY_RID2PASID_MASK) #define VTD_CE_GET_PASID_DIR_TABLE(ce) \ ((ce)->val[0] & VTD_PASID_DIR_BASE_ADDR_MASK) #define VTD_CE_GET_PRE(ce) \ @@ -958,15 +956,12 @@ static int vtd_ce_get_pasid_entry(IntelIOMMUState *s,= VTDContextEntry *ce, VTDPASIDEntry *pe, uint32_t pasid) { dma_addr_t pasid_dir_base; - int ret =3D 0; =20 if (pasid =3D=3D PCI_NO_PASID) { - pasid =3D VTD_CE_GET_RID2PASID(ce); + pasid =3D PASID_0; } pasid_dir_base =3D VTD_CE_GET_PASID_DIR_TABLE(ce); - ret =3D vtd_get_pe_from_pasid_table(s, pasid_dir_base, pasid, pe); - - return ret; + return vtd_get_pe_from_pasid_table(s, pasid_dir_base, pasid, pe); } =20 static int vtd_ce_get_pasid_fpd(IntelIOMMUState *s, @@ -980,7 +975,7 @@ static int vtd_ce_get_pasid_fpd(IntelIOMMUState *s, VTDPASIDEntry pe; =20 if (pasid =3D=3D PCI_NO_PASID) { - pasid =3D VTD_CE_GET_RID2PASID(ce); + pasid =3D PASID_0; } pasid_dir_base =3D VTD_CE_GET_PASID_DIR_TABLE(ce); =20 @@ -1520,17 +1515,15 @@ static inline int vtd_context_entry_rsvd_bits_check= (IntelIOMMUState *s, return 0; } =20 -static int vtd_ce_rid2pasid_check(IntelIOMMUState *s, - VTDContextEntry *ce) +static int vtd_ce_pasid_0_check(IntelIOMMUState *s, VTDContextEntry *ce) { VTDPASIDEntry pe; =20 /* * Make sure in Scalable Mode, a present context entry - * has valid rid2pasid setting, which includes valid - * rid2pasid field and corresponding pasid entry setting + * has valid pasid entry setting at PASID_0. */ - return vtd_ce_get_pasid_entry(s, ce, &pe, PCI_NO_PASID); + return vtd_ce_get_pasid_entry(s, ce, &pe, PASID_0); } =20 /* Map a device to its corresponding domain (context-entry) */ @@ -1591,15 +1584,11 @@ static int vtd_dev_to_context_entry(IntelIOMMUState= *s, uint8_t bus_num, } } else { /* - * Check if the programming of context-entry.rid2pasid - * and corresponding pasid setting is valid, and thus - * avoids to check pasid entry fetching result in future - * helper function calling. + * Check if the programming of pasid setting of PASID_0 + * is valid, and thus avoids to check pasid entry fetching + * result in future helper function calling. */ - ret_fr =3D vtd_ce_rid2pasid_check(s, ce); - if (ret_fr) { - return ret_fr; - } + return vtd_ce_pasid_0_check(s, ce); } =20 return 0; @@ -2108,7 +2097,6 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, bool reads =3D true; bool writes =3D true; uint8_t access_flags, pgtt; - bool rid2pasid =3D (pasid =3D=3D PCI_NO_PASID) && s->root_scalable; VTDIOTLBEntry *iotlb_entry; uint64_t xlat, size; =20 @@ -2120,21 +2108,23 @@ static bool vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, =20 vtd_iommu_lock(s); =20 - cc_entry =3D &vtd_as->context_cache_entry; + if (pasid =3D=3D PCI_NO_PASID && s->root_scalable) { + pasid =3D PASID_0; + } =20 - /* Try to fetch pte from IOTLB, we don't need RID2PASID logic */ - if (!rid2pasid) { - iotlb_entry =3D vtd_lookup_iotlb(s, source_id, pasid, addr); - if (iotlb_entry) { - trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->pte, - iotlb_entry->domain_id); - pte =3D iotlb_entry->pte; - access_flags =3D iotlb_entry->access_flags; - page_mask =3D iotlb_entry->mask; - goto out; - } + /* Try to fetch pte from IOTLB */ + iotlb_entry =3D vtd_lookup_iotlb(s, source_id, pasid, addr); + if (iotlb_entry) { + trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->pte, + iotlb_entry->domain_id); + pte =3D iotlb_entry->pte; + access_flags =3D iotlb_entry->access_flags; + page_mask =3D iotlb_entry->mask; + goto out; } =20 + cc_entry =3D &vtd_as->context_cache_entry; + /* Try to fetch context-entry from cache first */ if (cc_entry->context_cache_gen =3D=3D s->context_cache_gen) { trace_vtd_iotlb_cc_hit(bus_num, devfn, cc_entry->context_entry.hi, @@ -2171,10 +2161,6 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *= vtd_as, PCIBus *bus, cc_entry->context_cache_gen =3D s->context_cache_gen; } =20 - if (rid2pasid) { - pasid =3D VTD_CE_GET_RID2PASID(&ce); - } - /* * We don't need to translate for pass-through context entries. * Also, let's ignore IOTLB caching as well for PT devices. @@ -2200,19 +2186,6 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *= vtd_as, PCIBus *bus, return true; } =20 - /* Try to fetch pte from IOTLB for RID2PASID slow path */ - if (rid2pasid) { - iotlb_entry =3D vtd_lookup_iotlb(s, source_id, pasid, addr); - if (iotlb_entry) { - trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->pte, - iotlb_entry->domain_id); - pte =3D iotlb_entry->pte; - access_flags =3D iotlb_entry->access_flags; - page_mask =3D iotlb_entry->mask; - goto out; - } - } - if (s->flts && s->root_scalable) { ret_fr =3D vtd_iova_to_flpte(s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid); @@ -2475,20 +2448,14 @@ static void vtd_iotlb_page_invalidate_notify(IntelI= OMMUState *s, ret =3D vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), vtd_as->devfn, &ce); if (!ret && domain_id =3D=3D vtd_get_domain_id(s, &ce, vtd_as->pas= id)) { - uint32_t rid2pasid =3D PCI_NO_PASID; - - if (s->root_scalable) { - rid2pasid =3D VTD_CE_GET_RID2PASID(&ce); - } - /* * In legacy mode, vtd_as->pasid =3D=3D pasid is always true. * In scalable mode, for vtd address space backing a PCI * device without pasid, needs to compare pasid with - * rid2pasid of this device. + * PASID_0 of this device. */ if (!(vtd_as->pasid =3D=3D pasid || - (vtd_as->pasid =3D=3D PCI_NO_PASID && pasid =3D=3D rid2p= asid))) { + (vtd_as->pasid =3D=3D PCI_NO_PASID && pasid =3D=3D PASID= _0))) { continue; } =20 @@ -2993,9 +2960,7 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUSta= te *s, if (!vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), vtd_as->devfn, &ce) && domain_id =3D=3D vtd_get_domain_id(s, &ce, vtd_as->pasid)) { - uint32_t rid2pasid =3D VTD_CE_GET_RID2PASID(&ce); - - if ((vtd_as->pasid !=3D PCI_NO_PASID || pasid !=3D rid2pasid) = && + if ((vtd_as->pasid !=3D PCI_NO_PASID || pasid !=3D PASID_0) && vtd_as->pasid !=3D pasid) { continue; } --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297050; cv=none; d=zohomail.com; s=zohoarc; b=dy9Dr75pSDLcBR84svOd3pVWsDatQagRLbQvrM9qeULRW7k1/gWb8zOLcNbzkt/almC7MvghWJEaiZfM9YcQWwg/vt5AMJ/PJBJpKdwdIqboXKv73NPxwHPOYkeLvPKwEiiHCqB8W+nccRa0vfQIyPf+/r5dEurK7p1r3C1IUZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297050; 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=NRSLCrD6y0cGQRZguX8Qs/EwmrJsjXW1zjVUPhtpLyU=; b=iJ7z2X/7Z5vxpbWVcj14HxHYUIhv/kpe1QTcMvLqzOCg8ZV11ty/YoUfc2MSsIlVi317ccizbNSsrC6n4TYnJ8Ov1OAB0hj5c3NlcA0P6gxva7F8QmmWZtlZ6mftRFUENqlyRXz/eDdGM5SSiyimox15/ZV2afyzWYQUTaY/XUU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297050070337.87745813421543; Tue, 13 Jan 2026 01:37:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfapm-0006aG-G5; Tue, 13 Jan 2026 04:37:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapl-0006ZM-3W for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaph-0003H9-8t for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:04 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-DOYFvc-1OaCGcZeKILvsQw-1; Tue, 13 Jan 2026 04:36:57 -0500 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EC32218002E2; Tue, 13 Jan 2026 09:36:55 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 805D830001A2; Tue, 13 Jan 2026 09:36:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297020; 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=NRSLCrD6y0cGQRZguX8Qs/EwmrJsjXW1zjVUPhtpLyU=; b=jWVtPAzllR3vQdxvbj1jSlt2rTQVdY6HaWJ8Piur3y5ycEh7DPUab/QP9IA+51Du4p7qnw G0bB7iz1+2ZOPULT0cRSX486uRfo0RJY+MnOJ54rwNZ2HQcTPRcXEoToeFbmNJBvUKZbLV lkI9PZplyFbNeFGzUelIspCNhwVjjoE= X-MC-Unique: DOYFvc-1OaCGcZeKILvsQw-1 X-Mimecast-MFC-AGG-ID: DOYFvc-1OaCGcZeKILvsQw_1768297016 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , Eric Auger , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 05/41] intel_iommu: Update terminology to match VTD spec Date: Tue, 13 Jan 2026 10:36:01 +0100 Message-ID: <20260113093637.1549214-6-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297051528158500 From: Zhenzhong Duan VTD spec revision 3.4 released in December 2021 renamed "First-level" to "First-stage" and "Second-level" to "Second-stage". Do the same in intel_iommu code to match spec, change all existing "fl/sl/FL/SL/first level/second level/stage-1/stage-2" terminology to "fs/ss/FS/SS/first stage/second stage". Opportunistically fix a error print of "flts=3Don" with "x-flts=3Don". No functional changes intended. Suggested-by: Yi Liu Suggested-by: Eric Auger Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-4-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_internal.h | 85 ++++++------ include/hw/i386/intel_iommu.h | 2 +- hw/i386/intel_iommu.c | 247 +++++++++++++++++---------------- tests/qtest/intel-iommu-test.c | 4 +- 4 files changed, 170 insertions(+), 168 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 36d04427dd7a8c0e8ebe6ebc3c5f742eefa7ce9b..3330298884d598a0fcba80231d2= 35cd4c1053c6d 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -196,8 +196,8 @@ #define VTD_ECAP_PSS (7ULL << 35) /* limit: MemTxAttrs::pid= */ #define VTD_ECAP_PASID (1ULL << 40) #define VTD_ECAP_SMTS (1ULL << 43) -#define VTD_ECAP_SLTS (1ULL << 46) -#define VTD_ECAP_FLTS (1ULL << 47) +#define VTD_ECAP_SSTS (1ULL << 46) +#define VTD_ECAP_FSTS (1ULL << 47) =20 /* CAP_REG */ /* (offset >> 4) << 24 */ @@ -211,7 +211,7 @@ #define VTD_MAMV 18ULL #define VTD_CAP_MAMV (VTD_MAMV << 48) #define VTD_CAP_PSI (1ULL << 39) -#define VTD_CAP_SLLPS ((1ULL << 34) | (1ULL << 35)) +#define VTD_CAP_SSLPS ((1ULL << 34) | (1ULL << 35)) #define VTD_CAP_DRAIN_WRITE (1ULL << 54) #define VTD_CAP_DRAIN_READ (1ULL << 55) #define VTD_CAP_FS1GP (1ULL << 56) @@ -284,7 +284,7 @@ typedef enum VTDFaultReason { VTD_FR_ADDR_BEYOND_MGAW, /* Input-address above (2^x-1) */ VTD_FR_WRITE, /* No write permission */ VTD_FR_READ, /* No read permission */ - /* Fail to access a second-level paging entry (not SL_PML4E) */ + /* Fail to access a second-stage paging entry (not SS_PML4E) */ VTD_FR_PAGING_ENTRY_INV, VTD_FR_ROOT_TABLE_INV, /* Fail to access a root-entry */ VTD_FR_CONTEXT_TABLE_INV, /* Fail to access a context-entry */ @@ -292,7 +292,8 @@ typedef enum VTDFaultReason { VTD_FR_ROOT_ENTRY_RSVD, /* Non-zero reserved field in a present context-entry */ VTD_FR_CONTEXT_ENTRY_RSVD, - /* Non-zero reserved field in a second-level paging entry with at leas= e one + /* + * Non-zero reserved field in a second-stage paging entry with at leas= e one * Read(R) and Write(W) or Execute(E) field is Set. */ VTD_FR_PAGING_ENTRY_RSVD, @@ -329,7 +330,7 @@ typedef enum VTDFaultReason { VTD_FR_PASID_ENTRY_P =3D 0x59, VTD_FR_PASID_TABLE_ENTRY_INV =3D 0x5b, /*Invalid PASID table entry */ =20 - /* Fail to access a first-level paging entry (not FS_PML4E) */ + /* Fail to access a first-stage paging entry (not FS_PML4E) */ VTD_FR_FS_PAGING_ENTRY_INV =3D 0x70, VTD_FR_FS_PAGING_ENTRY_P =3D 0x71, /* Non-zero reserved field in present first-stage paging entry */ @@ -473,23 +474,23 @@ typedef union VTDPRDesc VTDPRDesc; =20 #define VTD_SPTE_PAGE_L1_RSVD_MASK(aw, stale_tm) \ stale_tm ? \ - (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM)) : \ - (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM | VTD_SS_TM)) : \ + (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) #define VTD_SPTE_PAGE_L2_RSVD_MASK(aw) \ - (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) #define VTD_SPTE_PAGE_L3_RSVD_MASK(aw) \ - (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) #define VTD_SPTE_PAGE_L4_RSVD_MASK(aw) \ - (0x880ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x880ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) =20 #define VTD_SPTE_LPAGE_L2_RSVD_MASK(aw, stale_tm) \ stale_tm ? \ - (0x1ff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM)) := \ - (0x1ff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x1ff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM | VTD_SS_TM)) := \ + (0x1ff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) #define VTD_SPTE_LPAGE_L3_RSVD_MASK(aw, stale_tm) \ stale_tm ? \ - (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM))= : \ - (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) + (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM | VTD_SS_TM))= : \ + (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SS_IGN_COM)) =20 /* Rsvd field masks for fpte */ #define VTD_FS_UPPER_IGNORED 0xfff0000000000000ULL @@ -596,8 +597,8 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_CONTEXT_TT_MULTI_LEVEL 0 #define VTD_CONTEXT_TT_DEV_IOTLB (1ULL << 2) #define VTD_CONTEXT_TT_PASS_THROUGH (2ULL << 2) -/* Second Level Page Translation Pointer*/ -#define VTD_CONTEXT_ENTRY_SLPTPTR (~0xfffULL) +/* Second Stage Page Translation Pointer*/ +#define VTD_CONTEXT_ENTRY_SSPTPTR (~0xfffULL) #define VTD_CONTEXT_ENTRY_RSVD_LO(aw) (0xff0ULL | ~VTD_HAW_MASK(aw)) /* hi */ #define VTD_CONTEXT_ENTRY_AW 7ULL /* Adjusted guest-address-width */ @@ -635,37 +636,37 @@ typedef struct VTDPASIDCacheInfo { /* PASID Granular Translation Type Mask */ #define VTD_PASID_ENTRY_P 1ULL #define VTD_SM_PASID_ENTRY_PGTT (7ULL << 6) -#define VTD_SM_PASID_ENTRY_FLT (1ULL << 6) -#define VTD_SM_PASID_ENTRY_SLT (2ULL << 6) +#define VTD_SM_PASID_ENTRY_FST (1ULL << 6) +#define VTD_SM_PASID_ENTRY_SST (2ULL << 6) #define VTD_SM_PASID_ENTRY_NESTED (3ULL << 6) #define VTD_SM_PASID_ENTRY_PT (4ULL << 6) =20 #define VTD_SM_PASID_ENTRY_AW 7ULL /* Adjusted guest-address-widt= h */ #define VTD_SM_PASID_ENTRY_DID(val) ((val) & VTD_DOMAIN_ID_MASK) =20 -#define VTD_SM_PASID_ENTRY_FLPM 3ULL -#define VTD_SM_PASID_ENTRY_FLPTPTR (~0xfffULL) - -/* First Level Paging Structure */ -/* Masks for First Level Paging Entry */ -#define VTD_FL_P 1ULL -#define VTD_FL_RW (1ULL << 1) -#define VTD_FL_US (1ULL << 2) -#define VTD_FL_A (1ULL << 5) -#define VTD_FL_D (1ULL << 6) - -/* Second Level Page Translation Pointer*/ -#define VTD_SM_PASID_ENTRY_SLPTPTR (~0xfffULL) - -/* Second Level Paging Structure */ -/* Masks for Second Level Paging Entry */ -#define VTD_SL_RW_MASK 3ULL -#define VTD_SL_R 1ULL -#define VTD_SL_W (1ULL << 1) -#define VTD_SL_IGN_COM 0xbff0000000000000ULL -#define VTD_SL_TM (1ULL << 62) - -/* Common for both First Level and Second Level */ +#define VTD_SM_PASID_ENTRY_FSPM 3ULL +#define VTD_SM_PASID_ENTRY_FSPTPTR (~0xfffULL) + +/* First Stage Paging Structure */ +/* Masks for First Stage Paging Entry */ +#define VTD_FS_P 1ULL +#define VTD_FS_RW (1ULL << 1) +#define VTD_FS_US (1ULL << 2) +#define VTD_FS_A (1ULL << 5) +#define VTD_FS_D (1ULL << 6) + +/* Second Stage Page Translation Pointer*/ +#define VTD_SM_PASID_ENTRY_SSPTPTR (~0xfffULL) + +/* Second Stage Paging Structure */ +/* Masks for Second Stage Paging Entry */ +#define VTD_SS_RW_MASK 3ULL +#define VTD_SS_R 1ULL +#define VTD_SS_W (1ULL << 1) +#define VTD_SS_IGN_COM 0xbff0000000000000ULL +#define VTD_SS_TM (1ULL << 62) + +/* Common for both First Stage and Second Stage */ #define VTD_PML4_LEVEL 4 #define VTD_PDP_LEVEL 3 #define VTD_PD_LEVEL 2 diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index ca7f7bb6618a151fc2b09a238e9505ac4ce7ab18..0b7832d25db39eb47078453a648= 81ba96a3e5c38 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -271,7 +271,7 @@ struct IntelIOMMUState { =20 bool caching_mode; /* RO - is cap CM enabled? */ bool scalable_mode; /* RO - is Scalable Mode supported? */ - bool flts; /* RO - is stage-1 translation support= ed? */ + bool fsts; /* RO - is first stage translation sup= ported? */ bool snoop_control; /* RO - is SNP filed supported? */ =20 dma_addr_t root; /* Current root table pointer */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 2d3673db3737ce1ad7dbd5ccfd06019ae1782ce0..7bec53a58722b3e7cbf02059734= b8d1613a94ed1 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -48,9 +48,9 @@ =20 /* pe operations */ #define VTD_PE_GET_TYPE(pe) ((pe)->val[0] & VTD_SM_PASID_ENTRY_PGTT) -#define VTD_PE_GET_FL_LEVEL(pe) \ - (4 + (((pe)->val[2] >> 2) & VTD_SM_PASID_ENTRY_FLPM)) -#define VTD_PE_GET_SL_LEVEL(pe) \ +#define VTD_PE_GET_FS_LEVEL(pe) \ + (4 + (((pe)->val[2] >> 2) & VTD_SM_PASID_ENTRY_FSPM)) +#define VTD_PE_GET_SS_LEVEL(pe) \ (2 + (((pe)->val[0] >> 2) & VTD_SM_PASID_ENTRY_AW)) =20 /* @@ -327,7 +327,7 @@ static gboolean vtd_hash_remove_by_page(gpointer key, g= pointer value, * nested (PGTT=3D011b) mapping associated with specified domain-id are * invalidated. Nested isn't supported yet, so only need to check 001b. */ - if (entry->pgtt =3D=3D VTD_SM_PASID_ENTRY_FLT) { + if (entry->pgtt =3D=3D VTD_SM_PASID_ENTRY_FST) { return true; } =20 @@ -348,7 +348,7 @@ static gboolean vtd_hash_remove_by_page_piotlb(gpointer= key, gpointer value, * or pass-through (PGTT=3D100b) mappings. Nested isn't supported yet, * so only need to check first-stage (PGTT=3D001b) mappings. */ - if (entry->pgtt !=3D VTD_SM_PASID_ENTRY_FLT) { + if (entry->pgtt !=3D VTD_SM_PASID_ENTRY_FST) { return false; } =20 @@ -756,9 +756,9 @@ static int vtd_get_context_entry_from_root(IntelIOMMUSt= ate *s, return 0; } =20 -static inline dma_addr_t vtd_ce_get_slpt_base(VTDContextEntry *ce) +static inline dma_addr_t vtd_ce_get_sspt_base(VTDContextEntry *ce) { - return ce->lo & VTD_CONTEXT_ENTRY_SLPTPTR; + return ce->lo & VTD_CONTEXT_ENTRY_SSPTPTR; } =20 static inline uint64_t vtd_get_pte_addr(uint64_t pte, uint8_t aw) @@ -799,13 +799,13 @@ static inline uint32_t vtd_iova_level_offset(uint64_t= iova, uint32_t level) } =20 /* Check Capability Register to see if the @level of page-table is support= ed */ -static inline bool vtd_is_sl_level_supported(IntelIOMMUState *s, uint32_t = level) +static inline bool vtd_is_ss_level_supported(IntelIOMMUState *s, uint32_t = level) { return VTD_CAP_SAGAW_MASK & s->cap & (1ULL << (level - 2 + VTD_CAP_SAGAW_SHIFT)); } =20 -static inline bool vtd_is_fl_level_supported(IntelIOMMUState *s, uint32_t = level) +static inline bool vtd_is_fs_level_supported(IntelIOMMUState *s, uint32_t = level) { return level =3D=3D VTD_PML4_LEVEL; } @@ -814,10 +814,10 @@ static inline bool vtd_is_fl_level_supported(IntelIOM= MUState *s, uint32_t level) static inline bool vtd_pe_type_check(IntelIOMMUState *s, VTDPASIDEntry *pe) { switch (VTD_PE_GET_TYPE(pe)) { - case VTD_SM_PASID_ENTRY_FLT: - return !!(s->ecap & VTD_ECAP_FLTS); - case VTD_SM_PASID_ENTRY_SLT: - return !!(s->ecap & VTD_ECAP_SLTS); + case VTD_SM_PASID_ENTRY_FST: + return !!(s->ecap & VTD_ECAP_FSTS); + case VTD_SM_PASID_ENTRY_SST: + return !!(s->ecap & VTD_ECAP_SSTS); case VTD_SM_PASID_ENTRY_NESTED: /* Not support NESTED page table type yet */ return false; @@ -889,13 +889,13 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUS= tate *s, } =20 pgtt =3D VTD_PE_GET_TYPE(pe); - if (pgtt =3D=3D VTD_SM_PASID_ENTRY_SLT && - !vtd_is_sl_level_supported(s, VTD_PE_GET_SL_LEVEL(pe))) { + if (pgtt =3D=3D VTD_SM_PASID_ENTRY_SST && + !vtd_is_ss_level_supported(s, VTD_PE_GET_SS_LEVEL(pe))) { return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 - if (pgtt =3D=3D VTD_SM_PASID_ENTRY_FLT && - !vtd_is_fl_level_supported(s, VTD_PE_GET_FL_LEVEL(pe))) { + if (pgtt =3D=3D VTD_SM_PASID_ENTRY_FST && + !vtd_is_fs_level_supported(s, VTD_PE_GET_FS_LEVEL(pe))) { return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 @@ -1013,7 +1013,8 @@ static int vtd_ce_get_pasid_fpd(IntelIOMMUState *s, return 0; } =20 -/* Get the page-table level that hardware should use for the second-level +/* + * Get the page-table level that hardware should use for the second-stage * page-table walk from the Address Width field of context-entry. */ static inline uint32_t vtd_ce_get_level(VTDContextEntry *ce) @@ -1029,10 +1030,10 @@ static uint32_t vtd_get_iova_level(IntelIOMMUState = *s, =20 if (s->root_scalable) { vtd_ce_get_pasid_entry(s, ce, &pe, pasid); - if (s->flts) { - return VTD_PE_GET_FL_LEVEL(&pe); + if (s->fsts) { + return VTD_PE_GET_FS_LEVEL(&pe); } else { - return VTD_PE_GET_SL_LEVEL(&pe); + return VTD_PE_GET_SS_LEVEL(&pe); } } =20 @@ -1101,7 +1102,7 @@ static inline uint64_t vtd_iova_limit(IntelIOMMUState= *s, } =20 /* Return true if IOVA passes range check, otherwise false. */ -static inline bool vtd_iova_sl_range_check(IntelIOMMUState *s, +static inline bool vtd_iova_ss_range_check(IntelIOMMUState *s, uint64_t iova, VTDContextEntry = *ce, uint8_t aw, uint32_t pasid) { @@ -1120,14 +1121,14 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMM= UState *s, =20 if (s->root_scalable) { vtd_ce_get_pasid_entry(s, ce, &pe, pasid); - if (s->flts) { - return pe.val[2] & VTD_SM_PASID_ENTRY_FLPTPTR; + if (s->fsts) { + return pe.val[2] & VTD_SM_PASID_ENTRY_FSPTPTR; } else { - return pe.val[0] & VTD_SM_PASID_ENTRY_SLPTPTR; + return pe.val[0] & VTD_SM_PASID_ENTRY_SSPTPTR; } } =20 - return vtd_ce_get_slpt_base(ce); + return vtd_ce_get_sspt_base(ce); } =20 /* @@ -1142,13 +1143,13 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMM= UState *s, static uint64_t vtd_spte_rsvd[VTD_SPTE_RSVD_LEN]; static uint64_t vtd_spte_rsvd_large[VTD_SPTE_RSVD_LEN]; =20 -static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) +static bool vtd_sspte_nonzero_rsvd(uint64_t sspte, uint32_t level) { uint64_t rsvd_mask; =20 /* * We should have caught a guest-mis-programmed level earlier, - * via vtd_is_sl_level_supported. + * via vtd_is_ss_level_supported. */ assert(level < VTD_SPTE_RSVD_LEN); /* @@ -1158,46 +1159,47 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, = uint32_t level) assert(level); =20 if ((level =3D=3D VTD_PD_LEVEL || level =3D=3D VTD_PDP_LEVEL) && - (slpte & VTD_PT_PAGE_SIZE_MASK)) { + (sspte & VTD_PT_PAGE_SIZE_MASK)) { /* large page */ rsvd_mask =3D vtd_spte_rsvd_large[level]; } else { rsvd_mask =3D vtd_spte_rsvd[level]; } =20 - return slpte & rsvd_mask; + return sspte & rsvd_mask; } =20 -/* Given the @iova, get relevant @slptep. @slpte_level will be the last le= vel +/* + * Given the @iova, get relevant @ssptep. @sspte_level will be the last le= vel * of the translation, can be used for deciding the size of large page. */ -static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce, +static int vtd_iova_to_sspte(IntelIOMMUState *s, VTDContextEntry *ce, uint64_t iova, bool is_write, - uint64_t *slptep, uint32_t *slpte_level, + uint64_t *ssptep, uint32_t *sspte_level, bool *reads, bool *writes, uint8_t aw_bits, uint32_t pasid) { dma_addr_t addr =3D vtd_get_iova_pgtbl_base(s, ce, pasid); uint32_t level =3D vtd_get_iova_level(s, ce, pasid); uint32_t offset; - uint64_t slpte; + uint64_t sspte; uint64_t access_right_check; =20 - if (!vtd_iova_sl_range_check(s, iova, ce, aw_bits, pasid)) { + if (!vtd_iova_ss_range_check(s, iova, ce, aw_bits, pasid)) { error_report_once("%s: detected IOVA overflow (iova=3D0x%" PRIx64 = "," "pasid=3D0x%" PRIx32 ")", __func__, iova, pasid); return -VTD_FR_ADDR_BEYOND_MGAW; } =20 /* FIXME: what is the Atomics request here? */ - access_right_check =3D is_write ? VTD_SL_W : VTD_SL_R; + access_right_check =3D is_write ? VTD_SS_W : VTD_SS_R; =20 while (true) { offset =3D vtd_iova_level_offset(iova, level); - slpte =3D vtd_get_pte(addr, offset); + sspte =3D vtd_get_pte(addr, offset); =20 - if (slpte =3D=3D (uint64_t)-1) { - error_report_once("%s: detected read error on DMAR slpte " + if (sspte =3D=3D (uint64_t)-1) { + error_report_once("%s: detected read error on DMAR sspte " "(iova=3D0x%" PRIx64 ", pasid=3D0x%" PRIx32 = ")", __func__, iova, pasid); if (level =3D=3D vtd_get_iova_level(s, ce, pasid)) { @@ -1207,30 +1209,30 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VT= DContextEntry *ce, return -VTD_FR_PAGING_ENTRY_INV; } } - *reads =3D (*reads) && (slpte & VTD_SL_R); - *writes =3D (*writes) && (slpte & VTD_SL_W); - if (!(slpte & access_right_check)) { - error_report_once("%s: detected slpte permission error " + *reads =3D (*reads) && (sspte & VTD_SS_R); + *writes =3D (*writes) && (sspte & VTD_SS_W); + if (!(sspte & access_right_check)) { + error_report_once("%s: detected sspte permission error " "(iova=3D0x%" PRIx64 ", level=3D0x%" PRIx32 = ", " - "slpte=3D0x%" PRIx64 ", write=3D%d, pasid=3D= 0x%" + "sspte=3D0x%" PRIx64 ", write=3D%d, pasid=3D= 0x%" PRIx32 ")", __func__, iova, level, - slpte, is_write, pasid); + sspte, is_write, pasid); return is_write ? -VTD_FR_WRITE : -VTD_FR_READ; } - if (vtd_slpte_nonzero_rsvd(slpte, level)) { + if (vtd_sspte_nonzero_rsvd(sspte, level)) { error_report_once("%s: detected splte reserve non-zero " "iova=3D0x%" PRIx64 ", level=3D0x%" PRIx32 - "slpte=3D0x%" PRIx64 ", pasid=3D0x%" PRIX32 = ")", - __func__, iova, level, slpte, pasid); + "sspte=3D0x%" PRIx64 ", pasid=3D0x%" PRIX32 = ")", + __func__, iova, level, sspte, pasid); return -VTD_FR_PAGING_ENTRY_RSVD; } =20 - if (vtd_is_last_pte(slpte, level)) { - *slptep =3D slpte; - *slpte_level =3D level; + if (vtd_is_last_pte(sspte, level)) { + *ssptep =3D sspte; + *sspte_level =3D level; break; } - addr =3D vtd_get_pte_addr(slpte, aw_bits); + addr =3D vtd_get_pte_addr(sspte, aw_bits); level--; } =20 @@ -1356,7 +1358,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint6= 4_t start, { bool read_cur, write_cur, entry_valid; uint32_t offset; - uint64_t slpte; + uint64_t sspte; uint64_t subpage_size, subpage_mask; IOMMUTLBEvent event; uint64_t iova =3D start; @@ -1372,21 +1374,21 @@ static int vtd_page_walk_level(dma_addr_t addr, uin= t64_t start, iova_next =3D (iova & subpage_mask) + subpage_size; =20 offset =3D vtd_iova_level_offset(iova, level); - slpte =3D vtd_get_pte(addr, offset); + sspte =3D vtd_get_pte(addr, offset); =20 - if (slpte =3D=3D (uint64_t)-1) { + if (sspte =3D=3D (uint64_t)-1) { trace_vtd_page_walk_skip_read(iova, iova_next); goto next; } =20 - if (vtd_slpte_nonzero_rsvd(slpte, level)) { + if (vtd_sspte_nonzero_rsvd(sspte, level)) { trace_vtd_page_walk_skip_reserve(iova, iova_next); goto next; } =20 /* Permissions are stacked with parents' */ - read_cur =3D read && (slpte & VTD_SL_R); - write_cur =3D write && (slpte & VTD_SL_W); + read_cur =3D read && (sspte & VTD_SS_R); + write_cur =3D write && (sspte & VTD_SS_W); =20 /* * As long as we have either read/write permission, this is a @@ -1395,12 +1397,12 @@ static int vtd_page_walk_level(dma_addr_t addr, uin= t64_t start, */ entry_valid =3D read_cur | write_cur; =20 - if (!vtd_is_last_pte(slpte, level) && entry_valid) { + if (!vtd_is_last_pte(sspte, level) && entry_valid) { /* * This is a valid PDE (or even bigger than PDE). We need * to walk one further level. */ - ret =3D vtd_page_walk_level(vtd_get_pte_addr(slpte, info->aw), + ret =3D vtd_page_walk_level(vtd_get_pte_addr(sspte, info->aw), iova, MIN(iova_next, end), level - 1, read_cur, write_cur, info); } else { @@ -1417,7 +1419,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint6= 4_t start, event.entry.perm =3D IOMMU_ACCESS_FLAG(read_cur, write_cur); event.entry.addr_mask =3D ~subpage_mask; /* NOTE: this is only meaningful if entry_valid =3D=3D true */ - event.entry.translated_addr =3D vtd_get_pte_addr(slpte, info->= aw); + event.entry.translated_addr =3D vtd_get_pte_addr(sspte, info->= aw); event.type =3D event.entry.perm ? IOMMU_NOTIFIER_MAP : IOMMU_NOTIFIER_UNMAP; ret =3D vtd_page_walk_one(&event, info); @@ -1451,11 +1453,11 @@ static int vtd_page_walk(IntelIOMMUState *s, VTDCon= textEntry *ce, dma_addr_t addr =3D vtd_get_iova_pgtbl_base(s, ce, pasid); uint32_t level =3D vtd_get_iova_level(s, ce, pasid); =20 - if (!vtd_iova_sl_range_check(s, start, ce, info->aw, pasid)) { + if (!vtd_iova_ss_range_check(s, start, ce, info->aw, pasid)) { return -VTD_FR_ADDR_BEYOND_MGAW; } =20 - if (!vtd_iova_sl_range_check(s, end, ce, info->aw, pasid)) { + if (!vtd_iova_ss_range_check(s, end, ce, info->aw, pasid)) { /* Fix end so that it reaches the maximum */ end =3D vtd_iova_limit(s, ce, info->aw, pasid); } @@ -1568,7 +1570,7 @@ static int vtd_dev_to_context_entry(IntelIOMMUState *= s, uint8_t bus_num, =20 /* Check if the programming of context-entry is valid */ if (!s->root_scalable && - !vtd_is_sl_level_supported(s, vtd_ce_get_level(ce))) { + !vtd_is_ss_level_supported(s, vtd_ce_get_level(ce))) { error_report_once("%s: invalid context entry: hi=3D%"PRIx64 ", lo=3D%"PRIx64" (level %d not supported)", __func__, ce->hi, ce->lo, @@ -1672,10 +1674,9 @@ static int vtd_address_space_sync(VTDAddressSpace *v= td_as) } =20 /* - * Check if specific device is configured to bypass address - * translation for DMA requests. In Scalable Mode, bypass - * 1st-level translation or 2nd-level translation, it depends - * on PGTT setting. + * Check if specific device is configured to bypass address translation + * for DMA requests. In Scalable Mode, bypass first stage translation + * or second stage translation, it depends on PGTT setting. */ static bool vtd_dev_pt_enabled(IntelIOMMUState *s, VTDContextEntry *ce, uint32_t pasid) @@ -1913,13 +1914,13 @@ out: static uint64_t vtd_fpte_rsvd[VTD_FPTE_RSVD_LEN]; static uint64_t vtd_fpte_rsvd_large[VTD_FPTE_RSVD_LEN]; =20 -static bool vtd_flpte_nonzero_rsvd(uint64_t flpte, uint32_t level) +static bool vtd_fspte_nonzero_rsvd(uint64_t fspte, uint32_t level) { uint64_t rsvd_mask; =20 /* * We should have caught a guest-mis-programmed level earlier, - * via vtd_is_fl_level_supported. + * via vtd_is_fs_level_supported. */ assert(level < VTD_FPTE_RSVD_LEN); /* @@ -1929,23 +1930,23 @@ static bool vtd_flpte_nonzero_rsvd(uint64_t flpte, = uint32_t level) assert(level); =20 if ((level =3D=3D VTD_PD_LEVEL || level =3D=3D VTD_PDP_LEVEL) && - (flpte & VTD_PT_PAGE_SIZE_MASK)) { + (fspte & VTD_PT_PAGE_SIZE_MASK)) { /* large page */ rsvd_mask =3D vtd_fpte_rsvd_large[level]; } else { rsvd_mask =3D vtd_fpte_rsvd[level]; } =20 - return flpte & rsvd_mask; + return fspte & rsvd_mask; } =20 -static inline bool vtd_flpte_present(uint64_t flpte) +static inline bool vtd_fspte_present(uint64_t fspte) { - return !!(flpte & VTD_FL_P); + return !!(fspte & VTD_FS_P); } =20 /* Return true if IOVA is canonical, otherwise false. */ -static bool vtd_iova_fl_check_canonical(IntelIOMMUState *s, uint64_t iova, +static bool vtd_iova_fs_check_canonical(IntelIOMMUState *s, uint64_t iova, VTDContextEntry *ce, uint32_t pasi= d) { uint64_t iova_limit =3D vtd_iova_limit(s, ce, s->aw_bits, pasid); @@ -1975,32 +1976,32 @@ static MemTxResult vtd_set_flag_in_pte(dma_addr_t b= ase_addr, uint32_t index, } =20 /* - * Given the @iova, get relevant @flptep. @flpte_level will be the last le= vel + * Given the @iova, get relevant @fsptep. @fspte_level will be the last le= vel * of the translation, can be used for deciding the size of large page. */ -static int vtd_iova_to_flpte(IntelIOMMUState *s, VTDContextEntry *ce, +static int vtd_iova_to_fspte(IntelIOMMUState *s, VTDContextEntry *ce, uint64_t iova, bool is_write, - uint64_t *flptep, uint32_t *flpte_level, + uint64_t *fsptep, uint32_t *fspte_level, bool *reads, bool *writes, uint8_t aw_bits, uint32_t pasid) { dma_addr_t addr =3D vtd_get_iova_pgtbl_base(s, ce, pasid); uint32_t offset; - uint64_t flpte, flag_ad =3D VTD_FL_A; - *flpte_level =3D vtd_get_iova_level(s, ce, pasid); + uint64_t fspte, flag_ad =3D VTD_FS_A; + *fspte_level =3D vtd_get_iova_level(s, ce, pasid); =20 - if (!vtd_iova_fl_check_canonical(s, iova, ce, pasid)) { + if (!vtd_iova_fs_check_canonical(s, iova, ce, pasid)) { error_report_once("%s: detected non canonical IOVA (iova=3D0x%" PR= Ix64 "," "pasid=3D0x%" PRIx32 ")", __func__, iova, pasid); return -VTD_FR_FS_NON_CANONICAL; } =20 while (true) { - offset =3D vtd_iova_level_offset(iova, *flpte_level); - flpte =3D vtd_get_pte(addr, offset); + offset =3D vtd_iova_level_offset(iova, *fspte_level); + fspte =3D vtd_get_pte(addr, offset); =20 - if (flpte =3D=3D (uint64_t)-1) { - if (*flpte_level =3D=3D vtd_get_iova_level(s, ce, pasid)) { + if (fspte =3D=3D (uint64_t)-1) { + if (*fspte_level =3D=3D vtd_get_iova_level(s, ce, pasid)) { /* Invalid programming of pasid-entry */ return -VTD_FR_PASID_ENTRY_FSPTPTR_INV; } else { @@ -2008,47 +2009,47 @@ static int vtd_iova_to_flpte(IntelIOMMUState *s, VT= DContextEntry *ce, } } =20 - if (!vtd_flpte_present(flpte)) { + if (!vtd_fspte_present(fspte)) { *reads =3D false; *writes =3D false; return -VTD_FR_FS_PAGING_ENTRY_P; } =20 /* No emulated device supports supervisor privilege request yet */ - if (!(flpte & VTD_FL_US)) { + if (!(fspte & VTD_FS_US)) { *reads =3D false; *writes =3D false; return -VTD_FR_FS_PAGING_ENTRY_US; } =20 *reads =3D true; - *writes =3D (*writes) && (flpte & VTD_FL_RW); - if (is_write && !(flpte & VTD_FL_RW)) { + *writes =3D (*writes) && (fspte & VTD_FS_RW); + if (is_write && !(fspte & VTD_FS_RW)) { return -VTD_FR_SM_WRITE; } - if (vtd_flpte_nonzero_rsvd(flpte, *flpte_level)) { - error_report_once("%s: detected flpte reserved non-zero " + if (vtd_fspte_nonzero_rsvd(fspte, *fspte_level)) { + error_report_once("%s: detected fspte reserved non-zero " "iova=3D0x%" PRIx64 ", level=3D0x%" PRIx32 - "flpte=3D0x%" PRIx64 ", pasid=3D0x%" PRIX32 = ")", - __func__, iova, *flpte_level, flpte, pasid); + "fspte=3D0x%" PRIx64 ", pasid=3D0x%" PRIX32 = ")", + __func__, iova, *fspte_level, fspte, pasid); return -VTD_FR_FS_PAGING_ENTRY_RSVD; } =20 - if (vtd_is_last_pte(flpte, *flpte_level) && is_write) { - flag_ad |=3D VTD_FL_D; + if (vtd_is_last_pte(fspte, *fspte_level) && is_write) { + flag_ad |=3D VTD_FS_D; } =20 - if (vtd_set_flag_in_pte(addr, offset, flpte, flag_ad) !=3D MEMTX_O= K) { + if (vtd_set_flag_in_pte(addr, offset, fspte, flag_ad) !=3D MEMTX_O= K) { return -VTD_FR_FS_BIT_UPDATE_FAILED; } =20 - if (vtd_is_last_pte(flpte, *flpte_level)) { - *flptep =3D flpte; + if (vtd_is_last_pte(fspte, *fspte_level)) { + *fsptep =3D fspte; return 0; } =20 - addr =3D vtd_get_pte_addr(flpte, aw_bits); - (*flpte_level)--; + addr =3D vtd_get_pte_addr(fspte, aw_bits); + (*fspte_level)--; } } =20 @@ -2186,14 +2187,14 @@ static bool vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, return true; } =20 - if (s->flts && s->root_scalable) { - ret_fr =3D vtd_iova_to_flpte(s, &ce, addr, is_write, &pte, &level, + if (s->fsts && s->root_scalable) { + ret_fr =3D vtd_iova_to_fspte(s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid); - pgtt =3D VTD_SM_PASID_ENTRY_FLT; + pgtt =3D VTD_SM_PASID_ENTRY_FST; } else { - ret_fr =3D vtd_iova_to_slpte(s, &ce, addr, is_write, &pte, &level, + ret_fr =3D vtd_iova_to_sspte(s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid); - pgtt =3D VTD_SM_PASID_ENTRY_SLT; + pgtt =3D VTD_SM_PASID_ENTRY_SST; } if (!ret_fr) { xlat =3D vtd_get_pte_addr(pte, s->aw_bits); @@ -2461,13 +2462,13 @@ static void vtd_iotlb_page_invalidate_notify(IntelI= OMMUState *s, =20 if (vtd_as_has_map_notifier(vtd_as)) { /* - * When stage-1 translation is off, as long as we have MAP + * When first stage translation is off, as long as we have= MAP * notifications registered in any of our IOMMU notifiers, * we need to sync the shadow page table. Otherwise VFIO * device attaches to nested page table instead of shadow * page table, so no need to sync. */ - if (!s->flts || !s->root_scalable) { + if (!s->fsts || !s->root_scalable) { vtd_sync_shadow_page_table_range(vtd_as, &ce, addr, si= ze); } } else { @@ -2965,7 +2966,7 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUSta= te *s, continue; } =20 - if (!s->flts || !vtd_as_has_map_notifier(vtd_as)) { + if (!s->fsts || !vtd_as_has_map_notifier(vtd_as)) { vtd_address_space_sync(vtd_as); } } @@ -4060,7 +4061,7 @@ static const Property vtd_properties[] =3D { VTD_HOST_ADDRESS_WIDTH), DEFINE_PROP_BOOL("caching-mode", IntelIOMMUState, caching_mode, FALSE), DEFINE_PROP_BOOL("x-scalable-mode", IntelIOMMUState, scalable_mode, FA= LSE), - DEFINE_PROP_BOOL("x-flts", IntelIOMMUState, flts, FALSE), + DEFINE_PROP_BOOL("x-flts", IntelIOMMUState, fsts, FALSE), DEFINE_PROP_BOOL("snoop-control", IntelIOMMUState, snoop_control, fals= e), DEFINE_PROP_BOOL("x-pasid-mode", IntelIOMMUState, pasid, false), DEFINE_PROP_BOOL("dma-drain", IntelIOMMUState, dma_drain, true), @@ -4585,12 +4586,13 @@ static bool vtd_check_hiod(IntelIOMMUState *s, Host= IOMMUDevice *hiod, return false; } =20 - if (!s->flts) { - /* All checks requested by VTD stage-2 translation pass */ + if (!s->fsts) { + /* All checks requested by VTD second stage translation pass */ return true; } =20 - error_setg(errp, "host device is uncompatible with stage-1 translation= "); + error_setg(errp, + "host device is uncompatible with first stage translation"); return false; } =20 @@ -4782,7 +4784,7 @@ static void vtd_cap_init(IntelIOMMUState *s) X86IOMMUState *x86_iommu =3D X86_IOMMU_DEVICE(s); =20 s->cap =3D VTD_CAP_FRO | VTD_CAP_NFR | VTD_CAP_ND | - VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SLLPS | + VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SSLPS | VTD_CAP_ESRTPS | VTD_CAP_MGAW(s->aw_bits); if (s->dma_drain) { s->cap |=3D VTD_CAP_DRAIN; @@ -4818,13 +4820,13 @@ static void vtd_cap_init(IntelIOMMUState *s) } =20 /* TODO: read cap/ecap from host to decide which cap to be exposed. */ - if (s->flts) { - s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_FLTS; + if (s->fsts) { + s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_FSTS; if (s->fs1gp) { s->cap |=3D VTD_CAP_FS1GP; } } else if (s->scalable_mode) { - s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_SRS | VTD_ECAP_SLTS; + s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_SRS | VTD_ECAP_SSTS; } =20 if (s->snoop_control) { @@ -5132,7 +5134,7 @@ static int vtd_pri_perform_implicit_invalidation(VTDA= ddressSpace *vtd_as, domain_id =3D VTD_SM_PASID_ENTRY_DID(pe.val[1]); ret =3D 0; switch (pgtt) { - case VTD_SM_PASID_ENTRY_FLT: + case VTD_SM_PASID_ENTRY_FST: vtd_piotlb_page_invalidate(s, domain_id, vtd_as->pasid, addr, 0); break; /* Room for other pgtt values */ @@ -5334,12 +5336,12 @@ static bool vtd_decide_config(IntelIOMMUState *s, E= rror **errp) } } =20 - if (!s->scalable_mode && s->flts) { + if (!s->scalable_mode && s->fsts) { error_setg(errp, "x-flts is only available in scalable mode"); return false; } =20 - if (!s->flts && s->aw_bits !=3D VTD_HOST_AW_39BIT && + if (!s->fsts && s->aw_bits !=3D VTD_HOST_AW_39BIT && s->aw_bits !=3D VTD_HOST_AW_48BIT) { error_setg(errp, "%s: supported values for aw-bits are: %d, %d", s->scalable_mode ? "Scalable mode(flts=3Doff)" : "Legac= y mode", @@ -5347,10 +5349,9 @@ static bool vtd_decide_config(IntelIOMMUState *s, Er= ror **errp) return false; } =20 - if (s->flts && s->aw_bits !=3D VTD_HOST_AW_48BIT) { - error_setg(errp, - "Scalable mode(flts=3Don): supported value for aw-bits = is: %d", - VTD_HOST_AW_48BIT); + if (s->fsts && s->aw_bits !=3D VTD_HOST_AW_48BIT) { + error_setg(errp, "Scalable mode(x-flts=3Don): supported value for " + "aw-bits is: %d", VTD_HOST_AW_48BIT); return false; } =20 diff --git a/tests/qtest/intel-iommu-test.c b/tests/qtest/intel-iommu-test.c index c521b3796eb86d598e977edd95796b1e1c8fd03d..e5cc6acaf0bd5338d84458320f6= 81ec38c067471 100644 --- a/tests/qtest/intel-iommu-test.c +++ b/tests/qtest/intel-iommu-test.c @@ -13,9 +13,9 @@ #include "hw/i386/intel_iommu_internal.h" =20 #define CAP_STAGE_1_FIXED1 (VTD_CAP_FRO | VTD_CAP_NFR | VTD_CAP_ND | \ - VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SLLPS) + VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SSLPS) #define ECAP_STAGE_1_FIXED1 (VTD_ECAP_QI | VTD_ECAP_IR | VTD_ECAP_IRO |= \ - VTD_ECAP_MHMV | VTD_ECAP_SMTS | VTD_ECAP_FLT= S) + VTD_ECAP_MHMV | VTD_ECAP_SMTS | VTD_ECAP_FST= S) =20 static inline uint64_t vtd_reg_readq(QTestState *s, uint64_t offset) { --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297055; cv=none; d=zohomail.com; s=zohoarc; b=n6bVwRugJ9Lo+xb4C9v9uEqZGy0lsOUoZZY8E5+Z0GakIYB9cGK9c+pyt8JOv6zZ4LzijTTaDzBapCE+JFyxwbtIT79edZgZ9T1+ZfvsI8IJI294XQ9Nx55veK+Xqt8HibMgIIRvM9V2DjOS7YY7+QaDUvtguDlUukvGLPqkawc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297055; 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=0wa9rGJeqlryTfU8/vEgaaNivp1IdGg23E4dxsNQfe0=; b=edKyNYPQY5gPUGKFREcA5MePlTwiNlHq0dWdUylJEjGXAHuahRyDjS2yynm/AMHU+qGzXJVvMAITJVpeg9ambGxMRHcPX/mMnL9Q/pvDbHIBgmOybdu8crCxbn+9DB/RAhXPegBXLnJI2b5Hjcud2PlJhbSLkFbHCjxad3MQtQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297055690347.3097123692862; Tue, 13 Jan 2026 01:37:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfapn-0006c7-0y; Tue, 13 Jan 2026 04:37:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapm-0006Zx-6n for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapk-0003Hn-MI for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:05 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-_IcZB80NP_qmwJIasC8-Nw-1; Tue, 13 Jan 2026 04:37:00 -0500 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3575F1800359; Tue, 13 Jan 2026 09:36:59 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 69D8230001A2; Tue, 13 Jan 2026 09:36:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297023; 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=0wa9rGJeqlryTfU8/vEgaaNivp1IdGg23E4dxsNQfe0=; b=OBQTF1kSJLs68oTbUoOcSYRwsO9nsD2aWjuABVHwoumFTiQdb72JrjkI9Rkdjr8ftwdPzt uRPytE9ktaaA4wUeElb5+dPQ/ue063aA8uClTeO3m9dBpS5NYWbs0HcbM8vptYpGpqzj0N z0gO8FWgWtQ6yqjWis8i6aYe2EcwwT8= X-MC-Unique: _IcZB80NP_qmwJIasC8-Nw-1 X-Mimecast-MFC-AGG-ID: _IcZB80NP_qmwJIasC8-Nw_1768297019 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Eric Auger , Nicolin Chen , Yi Liu , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 06/41] hw/pci: Export pci_device_get_iommu_bus_devfn() and return bool Date: Tue, 13 Jan 2026 10:36:02 +0100 Message-ID: <20260113093637.1549214-7-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297057402158500 From: Zhenzhong Duan Returns true if PCI device is aliased or false otherwise. This will be used in following patch to determine if a PCI device is under a PCI bridge. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-5-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/pci/pci.h | 2 ++ hw/pci/pci.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index b72e4845009f3e3af0f01a85979b2cc5a5432f56..b22d350ba299addb3fccf17c404= 2ed6e9bd53d0b 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -637,6 +637,8 @@ typedef struct PCIIOMMUOps { bool is_write); } PCIIOMMUOps; =20 +bool pci_device_get_iommu_bus_devfn(PCIDevice *dev, PCIBus **piommu_bus, + PCIBus **aliased_bus, int *aliased_dev= fn); AddressSpace *pci_device_iommu_address_space(PCIDevice *dev); bool pci_device_set_iommu_device(PCIDevice *dev, HostIOMMUDevice *hiod, Error **errp); diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 5996229c813c7fcc167f29175041dfe233aaa1b4..0d4cf906f048c10ff13135a7aec= 509ca1baabd42 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2869,20 +2869,21 @@ static void pci_device_class_base_init(ObjectClass = *klass, const void *data) * For call sites which don't need aliased BDF, passing NULL to * aliased_[bus|devfn] is allowed. * + * Returns true if PCI device RID is aliased or false otherwise. + * * @piommu_bus: return root #PCIBus backed by an IOMMU for the PCI device. * * @aliased_bus: return aliased #PCIBus of the PCI device, optional. * * @aliased_devfn: return aliased devfn of the PCI device, optional. */ -static void pci_device_get_iommu_bus_devfn(PCIDevice *dev, - PCIBus **piommu_bus, - PCIBus **aliased_bus, - int *aliased_devfn) +bool pci_device_get_iommu_bus_devfn(PCIDevice *dev, PCIBus **piommu_bus, + PCIBus **aliased_bus, int *aliased_dev= fn) { PCIBus *bus =3D pci_get_bus(dev); PCIBus *iommu_bus =3D bus; int devfn =3D dev->devfn; + bool aliased =3D false; =20 while (iommu_bus && !iommu_bus->iommu_ops && iommu_bus->parent_dev) { PCIBus *parent_bus =3D pci_get_bus(iommu_bus->parent_dev); @@ -2919,6 +2920,7 @@ static void pci_device_get_iommu_bus_devfn(PCIDevice = *dev, devfn =3D parent->devfn; bus =3D parent_bus; } + aliased =3D true; } =20 /* @@ -2953,6 +2955,8 @@ static void pci_device_get_iommu_bus_devfn(PCIDevice = *dev, if (aliased_devfn) { *aliased_devfn =3D devfn; } + + return aliased; } =20 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297059; cv=none; d=zohomail.com; s=zohoarc; b=OT8shv/PCcq95DMvAWMHtGi/pOp3zgpta1HQhxvZOrR0YecRGMlEeDgVZBu8VL+3da0y0cbKSVjJvQwCZUfALLcdBB3CAGjzCqysd0e81Q8JYAKuypDjiQpiy3jkwzgxveovdbgAV559qCreKRHCvW9B6jT+j/t5NZdRgEMOEVM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297059; 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=UYqenjYCfzNzCClz6T59UQB/S2AiR1c3NCrEgZD/k5U=; b=I5JPrbhcxI/pjuURc4owV30sE3J8VJEU7FqbVDJDCd2X4zTv0cBwtw/eEht8JCCBsyVVPzXYikJcJ8bzjfBHVlBtg5aLFsPXSJW9LawNg+iRfZFpmkQWgbERijKvzN3PJTpVY+yOGvcpkIFOv2DB8osFLRcLm3uVEhh2dY0Rvpw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297059777410.8258532412939; Tue, 13 Jan 2026 01:37:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfapo-0006ei-Rf; Tue, 13 Jan 2026 04:37:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapn-0006cK-3Y for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapl-0003Hu-AG for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:06 -0500 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-121-_a4rcI_LNounxYRdJdxzjQ-1; Tue, 13 Jan 2026 04:37:03 -0500 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 315A319560B1; Tue, 13 Jan 2026 09:37:02 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8CF6B30001A2; Tue, 13 Jan 2026 09:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297024; 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=UYqenjYCfzNzCClz6T59UQB/S2AiR1c3NCrEgZD/k5U=; b=Z8sOB8hMrIBPfC+e+cnhnSbgOj0Fh6Skv+02XflZK03zBh7/ukBIzEBS/pxYFEl1f2JzH8 O5m0rOXP3RqbzP7jxm4melinrXX7ItqsGY6ES9QeImMfli+BYIjgK+RUgfZ3JvhLhcHxnI SDPO9ai3etg2K60GpXYikg4A6g3Tz2k= X-MC-Unique: _a4rcI_LNounxYRdJdxzjQ-1 X-Mimecast-MFC-AGG-ID: _a4rcI_LNounxYRdJdxzjQ_1768297022 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , Nicolin Chen , Eric Auger , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , "Michael S. Tsirkin" Subject: [PULL 07/41] hw/pci: Introduce pci_device_get_viommu_flags() Date: Tue, 13 Jan 2026 10:36:03 +0100 Message-ID: <20260113093637.1549214-8-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297061462158500 From: Zhenzhong Duan Introduce a new PCIIOMMUOps optional callback, get_viommu_flags() which allows to retrieve flags exposed by a vIOMMU. The first planned vIOMMU device flag is VIOMMU_FLAG_WANT_NESTING_PARENT that advertises the support of HW nested stage translation scheme and wants other sub-system like VFIO's cooperation to create nesting parent HWPT. pci_device_get_viommu_flags() is a wrapper that can be called on a PCI device potentially protected by a vIOMMU. get_viommu_flags() is designed to return 64bit bitmap of purely vIOMMU flags which are only determined by user's configuration, no host capabilities involved. Reasons are: 1. host may has heterogeneous IOMMUs, each with different capabilities 2. this is migration friendly, return value is consistent between source and target. Note that this op will be invoked at the attach_device() stage, at which point host IOMMU capabilities are not yet forwarded to the vIOMMU through the set_iommu_device() callback that will be after the attach_device(). See below sequence: vfio_device_attach(): iommufd_cdev_attach(): pci_device_get_viommu_flags() for HW nesting cap create a nesting parent HWPT attach device to the HWPT vfio_device_hiod_create_and_realize() creating hiod ... pci_device_set_iommu_device(hiod) Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Nicolin Chen Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-6-zhenzhong.= duan@intel.com [ clg: include/hw/core/iommu.h: Changed Copyright date 2025 -> 2026 ] Signed-off-by: C=C3=A9dric Le Goater --- MAINTAINERS | 1 + include/hw/core/iommu.h | 25 +++++++++++++++++++++++++ include/hw/pci/pci.h | 22 ++++++++++++++++++++++ hw/pci/pci.c | 11 +++++++++++ 4 files changed, 59 insertions(+) create mode 100644 include/hw/core/iommu.h diff --git a/MAINTAINERS b/MAINTAINERS index d16e620e01e49ec7a862bd43f3bdacc92b251dc3..620b184aa5f91f8f86879cf22ea= be720a9fa33a3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2368,6 +2368,7 @@ F: include/system/iommufd.h F: backends/host_iommu_device.c F: include/system/host_iommu_device.h F: include/qemu/chardev_open.h +F: include/hw/core/iommu.h F: util/chardev_open.c F: docs/devel/vfio-iommufd.rst =20 diff --git a/include/hw/core/iommu.h b/include/hw/core/iommu.h new file mode 100644 index 0000000000000000000000000000000000000000..fcbbcd10150e6e675fb68c817e7= 86bf23b301892 --- /dev/null +++ b/include/hw/core/iommu.h @@ -0,0 +1,25 @@ +/* + * General vIOMMU flags + * + * Copyright (C) 2026 Intel Corporation. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_IOMMU_H +#define HW_IOMMU_H + +#include "qemu/bitops.h" + +/* + * Theoretical vIOMMU flags. Only determined by the vIOMMU device properti= es and + * independent on the actual host IOMMU capabilities they may depend on. E= ach + * flag can be an expectation or request to other sub-system or just a pure + * vIOMMU capability. vIOMMU can choose which flags to expose. + */ +enum viommu_flags { + /* vIOMMU needs nesting parent HWPT to create nested HWPT */ + VIOMMU_FLAG_WANT_NESTING_PARENT =3D BIT_ULL(0), +}; + +#endif /* HW_IOMMU_H */ diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index b22d350ba299addb3fccf17c4042ed6e9bd53d0b..868817cc05ae26832246269eb4a= 1637c8e6ae64b 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -462,6 +462,18 @@ typedef struct PCIIOMMUOps { * @devfn: device and function number of the PCI device. */ void (*unset_iommu_device)(PCIBus *bus, void *opaque, int devfn); + /** + * @get_viommu_flags: get vIOMMU flags + * + * Optional callback, if not implemented, then vIOMMU doesn't support + * exposing flags to other sub-system, e.g., VFIO. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * Returns: bitmap with each bit representing a vIOMMU flag defined in + * enum viommu_flags. + */ + uint64_t (*get_viommu_flags)(void *opaque); /** * @get_iotlb_info: get properties required to initialize a device IOT= LB. * @@ -644,6 +656,16 @@ bool pci_device_set_iommu_device(PCIDevice *dev, HostI= OMMUDevice *hiod, Error **errp); void pci_device_unset_iommu_device(PCIDevice *dev); =20 +/** + * pci_device_get_viommu_flags: get vIOMMU flags. + * + * Returns: bitmap with each bit representing a vIOMMU flag defined in + * enum viommu_flags. Or 0 if vIOMMU doesn't report any. + * + * @dev: PCI device pointer. + */ +uint64_t pci_device_get_viommu_flags(PCIDevice *dev); + /** * pci_iommu_get_iotlb_info: get properties required to initialize a * device IOTLB. diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 0d4cf906f048c10ff13135a7aec509ca1baabd42..a136e772a39fd3fb1b3631351db= ea710227bedfe 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -3021,6 +3021,17 @@ void pci_device_unset_iommu_device(PCIDevice *dev) } } =20 +uint64_t pci_device_get_viommu_flags(PCIDevice *dev) +{ + PCIBus *iommu_bus; + + pci_device_get_iommu_bus_devfn(dev, &iommu_bus, NULL, NULL); + if (iommu_bus && iommu_bus->iommu_ops->get_viommu_flags) { + return iommu_bus->iommu_ops->get_viommu_flags(iommu_bus->iommu_opa= que); + } + return 0; +} + int pci_pri_request_page(PCIDevice *dev, uint32_t pasid, bool priv_req, bool exec_req, hwaddr addr, bool lpig, uint16_t prgi, bool is_read, bool is_write) --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297087; cv=none; d=zohomail.com; s=zohoarc; b=KPk3XJBknMG5407oM9fETfwZxAYjdkrB6EKc2Nnfk9Vrnx8ryiIj63xgbNg304UtKSJ8kQw7mMLd8VFnqtH47AR26+AgzEikmDb0KEj7PkHEqRP8s2DluAjJmQsHYVe+Ijf6l1k/twRiisq8y+4cnPII5n45L0y4eQS/8hPc444= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297087; 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=AzcQn3ODHV+v085VDLif4nakqsbjXDjsAeKgDZNIfiQ=; b=bWUYpaEsK+llKCGubrybo116fISqtrVQypNntYHqxEHVHWIoqQhr254EQ+wvoKaoB+h1tc46jqsbemPhuGm7S0RupwpLEaXvJqgNayWAbiTLeTVIIJ6vUUt6JqzC7SLfHhprBZwRy4f+RIFEowj/xQ/808hhMCHKLo/wK4ey4n0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297087404602.9773057815844; Tue, 13 Jan 2026 01:38:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfapt-0006pb-QS; Tue, 13 Jan 2026 04:37:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaps-0006ls-4F for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapq-0003Io-HB for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:11 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-345-8JvNqaXwPxW320HQl2-bUA-1; Tue, 13 Jan 2026 04:37:06 -0500 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 90C4418005B7; Tue, 13 Jan 2026 09:37:05 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A24BA30001A2; Tue, 13 Jan 2026 09:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297029; 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=AzcQn3ODHV+v085VDLif4nakqsbjXDjsAeKgDZNIfiQ=; b=RA4nCObQsNtaVcRjBwQ7MtZxIgkEDRdzFamwGG5wFSqmJs4YrI/Og3ookFI1+MbTJdVDFm vedWI2ajZCtwVGFAro6wnTrp558e/y03iGQEDW7deo+/w1tnuh8MeMM7zjBRfkygl6MBl/ 6TTzzMaFNa+4mbNLLOGa9IMISzbxVik= X-MC-Unique: 8JvNqaXwPxW320HQl2-bUA-1 X-Mimecast-MFC-AGG-ID: 8JvNqaXwPxW320HQl2-bUA_1768297025 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , Eric Auger , Nicolin Chen , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 08/41] intel_iommu: Implement get_viommu_flags() callback Date: Tue, 13 Jan 2026 10:36:04 +0100 Message-ID: <20260113093637.1549214-9-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297089534158501 From: Zhenzhong Duan Implement get_viommu_flags() callback and expose a request for nesting parent HWPT for now. VFIO uses it to create nesting parent HWPT which is further used to create nested HWPT in vIOMMU. All these will be implemented in following patches. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-7-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 7bec53a58722b3e7cbf02059734b8d1613a94ed1..9ce1bab93c56cd3d303e24be43c= 6ae1e2c4716a0 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -24,6 +24,7 @@ #include "qemu/main-loop.h" #include "qapi/error.h" #include "hw/core/sysbus.h" +#include "hw/core/iommu.h" #include "intel_iommu_internal.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" @@ -4659,6 +4660,16 @@ static void vtd_dev_unset_iommu_device(PCIBus *bus, = void *opaque, int devfn) vtd_iommu_unlock(s); } =20 +static uint64_t vtd_get_viommu_flags(void *opaque) +{ + IntelIOMMUState *s =3D opaque; + uint64_t flags; + + flags =3D s->fsts ? VIOMMU_FLAG_WANT_NESTING_PARENT : 0; + + return flags; +} + /* Unmap the whole range in the notifier's scope. */ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) { @@ -5312,6 +5323,7 @@ static PCIIOMMUOps vtd_iommu_ops =3D { .pri_register_notifier =3D vtd_pri_register_notifier, .pri_unregister_notifier =3D vtd_pri_unregister_notifier, .pri_request_page =3D vtd_pri_request_page, + .get_viommu_flags =3D vtd_get_viommu_flags, }; =20 static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297108; cv=none; d=zohomail.com; s=zohoarc; b=GQ5w9AgmzeouWrKX6qFJvEiEKkqB1Y+gImBRMhnblL69jhOvj0JU9mdWGhiUw+Omq9JDEJ0bagDjP6eSuC2UhAPttIePUAtedDDCCS0BeaMpSy2YZGMzR3zf0upa4lQZL+kNe3TurQhzjsSwEMFIxIPRYXYXIu9YWa17gBlXlsk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297108; 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=PVM8lXs/owQm/kANCC9AAoKIj8k8M6e8/O7my/HO0e8=; b=TQbQyjdchMPdJphJoDS5/sDuUdTY1Ap6zzgReFfgSeh3UDA5N3G5IEGFR8sSXJHptGJXS+M66LKsqSKaj8lR+J2XweCnwIPyCtrlbkCcS6ppOrdDGs9Plg/HEiAIfXonziVIeI1kmpL8cjNw4EgAz1JMLeNc6il6UO7Z1d3M5io= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297108529282.29587833612163; Tue, 13 Jan 2026 01:38:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfapy-0006xp-4S; Tue, 13 Jan 2026 04:37:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapx-0006uU-11 for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapv-0003JN-9N for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:16 -0500 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-601-2BbLbXAaMRWSwwMJ32AVBQ-1; Tue, 13 Jan 2026 04:37:10 -0500 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 DB77319541B9; Tue, 13 Jan 2026 09:37:08 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0E18F30001A2; Tue, 13 Jan 2026 09:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297034; 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=PVM8lXs/owQm/kANCC9AAoKIj8k8M6e8/O7my/HO0e8=; b=U4AtGWFGjGwLxEVLrndekCJVMR8k8i8Vk0uIbb57FDb40a/STSJ/Sn5Unsi971Wlu8Yxnf bJT3u3O3HEI8+urfzEbvGvdef9QZ8ne0NvWoZKfFcVxj50D+8j2glABtwrTzhEsm9jWXnL TP07j7/I/8SRv0ql6THrW0hIBOkZ7Do= X-MC-Unique: 2BbLbXAaMRWSwwMJ32AVBQ-1 X-Mimecast-MFC-AGG-ID: 2BbLbXAaMRWSwwMJ32AVBQ_1768297029 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Eric Auger , Nicolin Chen , Yi Liu , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 09/41] intel_iommu: Introduce a new structure VTDHostIOMMUDevice Date: Tue, 13 Jan 2026 10:36:05 +0100 Message-ID: <20260113093637.1549214-10-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297109786158500 From: Zhenzhong Duan Introduce a new structure VTDHostIOMMUDevice which replaces HostIOMMUDevice to be stored in hash table. It includes a reference to HostIOMMUDevice and IntelIOMMUState, also includes BDF information which will be used in future patches. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-8-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_internal.h | 7 +++++++ include/hw/i386/intel_iommu.h | 2 +- hw/i386/intel_iommu.c | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 3330298884d598a0fcba80231d235cd4c1053c6d..02522f64e0796dfcb40945e6296= 1d60be24a98ae 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -28,6 +28,7 @@ #ifndef HW_I386_INTEL_IOMMU_INTERNAL_H #define HW_I386_INTEL_IOMMU_INTERNAL_H #include "hw/i386/intel_iommu.h" +#include "system/host_iommu_device.h" =20 /* * Intel IOMMU register specification @@ -678,4 +679,10 @@ typedef struct VTDPASIDCacheInfo { /* Bits to decide the offset for each level */ #define VTD_LEVEL_BITS 9 =20 +typedef struct VTDHostIOMMUDevice { + IntelIOMMUState *iommu_state; + PCIBus *bus; + uint8_t devfn; + HostIOMMUDevice *hiod; +} VTDHostIOMMUDevice; #endif diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 0b7832d25db39eb47078453a64881ba96a3e5c38..401322665ac8e1a25330825b9e5= 06d3942249c92 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -302,7 +302,7 @@ struct IntelIOMMUState { /* list of registered notifiers */ QLIST_HEAD(, VTDAddressSpace) vtd_as_with_notifiers; =20 - GHashTable *vtd_host_iommu_dev; /* HostIOMMUDevice */ + GHashTable *vtd_host_iommu_dev; /* VTDHostIOMMUDevice */ =20 /* interrupt remapping */ bool intr_enabled; /* Whether guest enabled IR */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 9ce1bab93c56cd3d303e24be43c6ae1e2c4716a0..3a3725e489595121b1fdb0f38a1= e85fa7f64c1f6 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -288,7 +288,10 @@ static gboolean vtd_hiod_equal(gconstpointer v1, gcons= tpointer v2) =20 static void vtd_hiod_destroy(gpointer v) { - object_unref(v); + VTDHostIOMMUDevice *vtd_hiod =3D v; + + object_unref(vtd_hiod->hiod); + g_free(vtd_hiod); } =20 static gboolean vtd_hash_remove_by_domain(gpointer key, gpointer value, @@ -4601,6 +4604,7 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, voi= d *opaque, int devfn, HostIOMMUDevice *hiod, Error **errp) { IntelIOMMUState *s =3D opaque; + VTDHostIOMMUDevice *vtd_hiod; struct vtd_as_key key =3D { .bus =3D bus, .devfn =3D devfn, @@ -4623,7 +4627,14 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, vo= id *opaque, int devfn, return false; } =20 + vtd_hiod =3D g_malloc0(sizeof(VTDHostIOMMUDevice)); + vtd_hiod->bus =3D bus; + vtd_hiod->devfn =3D (uint8_t)devfn; + vtd_hiod->iommu_state =3D s; + vtd_hiod->hiod =3D hiod; + if (!vtd_check_hiod(s, hiod, errp)) { + g_free(vtd_hiod); vtd_iommu_unlock(s); return false; } @@ -4633,7 +4644,7 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, voi= d *opaque, int devfn, new_key->devfn =3D devfn; =20 object_ref(hiod); - g_hash_table_insert(s->vtd_host_iommu_dev, new_key, hiod); + g_hash_table_insert(s->vtd_host_iommu_dev, new_key, vtd_hiod); =20 vtd_iommu_unlock(s); =20 --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297058; cv=none; d=zohomail.com; s=zohoarc; b=BdPBhYbXTkjHy54v8xwWO4448lqxy7VWxGGkzdmUBXKtXdK+78XyiPzLBavVJnQOIsLb9E0ubUL1olX7/cdeEHQGNiqludebsVjHdDirrv+ylU2g7VS592zlKiRRVvjtcSHHWi/8rxyh+bGk3NMY1JgrPGHpQ/jbxKtxPBzPQXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297058; 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=YAAkMjBnQviAul+PLoRMDnmUXLCTqeSYmGEpKt8bFvo=; b=Kle2ow3U3WQe5H53CmkkSTISImplz20IDCLGU0rK3l2b7WrW3Aaaem4lSVFaLznlgZTnAeCv649F/ha22oQ/VjPlFRNC3ht1KopHGmSl0gPxLB7Q+NH3SDz8P7EPzEUpf9lMpNKAAKmiHy9+aAV15JbGWM+aTGoKup+SprOx3X8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297058742840.321594491629; Tue, 13 Jan 2026 01:37:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaq0-00075s-Lx; Tue, 13 Jan 2026 04:37:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapy-00070Z-Nl for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfapx-0003Ja-5x for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:18 -0500 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-131-N2dWqaezO2qsIr4-xrTfgg-1; Tue, 13 Jan 2026 04:37:13 -0500 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 0CF62195609E; Tue, 13 Jan 2026 09:37:12 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5912530001A8; Tue, 13 Jan 2026 09:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297036; 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=YAAkMjBnQviAul+PLoRMDnmUXLCTqeSYmGEpKt8bFvo=; b=chvPSV45VacHaqQ0HnZO2Dv4WfZYCpCjC6T1vR7Ycj2XeamulVGJ7fXQT1hqe16Gu6Ob/9 hx1xr6EpcdzcuwRgpUYE3EFxnqxmN4a2PxPaHnciEODHQsvvvBrZNLKwRia2I9v8mr8S74 RNHP1Bu34FZHt2Zt8Zj9OOI6qdX3GOM= X-MC-Unique: N2dWqaezO2qsIr4-xrTfgg-1 X-Mimecast-MFC-AGG-ID: N2dWqaezO2qsIr4-xrTfgg_1768297032 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Nicolin Chen , Yi Liu , Eric Auger , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 10/41] vfio/iommufd: Force creating nesting parent HWPT Date: Tue, 13 Jan 2026 10:36:06 +0100 Message-ID: <20260113093637.1549214-11-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297059514158500 From: Zhenzhong Duan Call pci_device_get_viommu_flags() to get if vIOMMU supports VIOMMU_FLAG_WANT_NESTING_PARENT. If yes, create a nesting parent HWPT and add it to the container's hwpt_lis= t, letting this parent HWPT cover the entire second stage mappings (GPA=3D>HPA= ). This allows a VFIO passthrough device to directly attach to this default HW= PT and then to use the system address space and its listener. Introduce a vfio_device_get_viommu_flags_want_nesting() helper to facilitate this implementation. It is safe to do so because a vIOMMU will be able to fail in set_iommu_devi= ce() call, if something else related to the VFIO device or vIOMMU isn't compatib= le. Suggested-by: Nicolin Chen Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Nicolin Chen Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-9-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-device.h | 2 ++ hw/vfio/device.c | 12 ++++++++++++ hw/vfio/iommufd.c | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 0fe6c60ba2d65b0ef5de5ef0c75c43cfa8e89352..0bc877ff62f9473d49782ce7c2e= e1eb943175821 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -257,6 +257,8 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOCont= ainer *bcontainer, =20 void vfio_device_unprepare(VFIODevice *vbasedev); =20 +bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev); + int vfio_device_get_region_info(VFIODevice *vbasedev, int index, struct vfio_region_info **info); int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type, diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 19d1236ed750d482280225b1db3e4f5c13a39a89..100532f35d9ad14bf14c8d6d783= f7b06aa85245a 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -23,6 +23,7 @@ =20 #include "hw/vfio/vfio-device.h" #include "hw/vfio/pci.h" +#include "hw/core/iommu.h" #include "hw/core/hw-error.h" #include "trace.h" #include "qapi/error.h" @@ -515,6 +516,17 @@ void vfio_device_unprepare(VFIODevice *vbasedev) vbasedev->bcontainer =3D NULL; } =20 +bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev) +{ + VFIOPCIDevice *vdev =3D vfio_pci_from_vfio_device(vbasedev); + + if (vdev) { + return !!(pci_device_get_viommu_flags(PCI_DEVICE(vdev)) & + VIOMMU_FLAG_WANT_NESTING_PARENT); + } + return false; +} + /* * Traditional ioctl() based io */ diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 32e8615ad3b41bdbeb6426c2542f445d9f31f2f5..e5328c63a366076199015b25f55= d273b91a4327a 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -361,6 +361,15 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, flags =3D IOMMU_HWPT_ALLOC_DIRTY_TRACKING; } =20 + /* + * If vIOMMU requests VFIO's cooperation to create nesting parent HWPT, + * force to create it so that it could be reused by vIOMMU to create + * nested HWPT. + */ + if (vfio_device_get_viommu_flags_want_nesting(vbasedev)) { + flags |=3D IOMMU_HWPT_ALLOC_NEST_PARENT; + } + if (cpr_is_incoming()) { hwpt_id =3D vbasedev->cpr.hwpt_id; goto skip_alloc; --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297096; cv=none; d=zohomail.com; s=zohoarc; b=duA95E9EJrTYDOWn012ecMz80MJCL8zTjiF6wADp0bBmSSOrIigoauaNpaY5t/RXmlFyyWCxxCjJmkWAbzWk9eYS+HwVRpKtLK8Sh1cgCTBX3OF/qO6KqYzDfid3RnpF6OcfbepWAWkf6K41n6+jGom+0OyF/cP2a6ocoQcThjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297096; 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=16go3Zbvd/Ek1pzySnrk2h8UNixWr9Z1NFH46NMmfv4=; b=PVCA4K+/0MWo2Fs0eXLrlEKzfV7tw09sQPTM4XKJ/ttsrZkpD2E+NYNIma9DrFaiXaX5anQ/J1jNFK9TetO9wTuranLsVHdh2oJx5LjhucWSQIZ8UlDLXRZq0tHgukG18Cx/K2Ka1KjS8C5kdR1jaIxU47I1nNex6yb9UfRh/40= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297096722558.3319700508359; Tue, 13 Jan 2026 01:38:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqF-0007sZ-KO; Tue, 13 Jan 2026 04:37:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqD-0007jf-UY for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqC-0003LX-2d for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:33 -0500 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-150-D55bB6I2OqW56sw30bozIA-1; Tue, 13 Jan 2026 04:37:16 -0500 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 0589E1956088; Tue, 13 Jan 2026 09:37:15 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7CF0630001A2; Tue, 13 Jan 2026 09:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297051; 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=16go3Zbvd/Ek1pzySnrk2h8UNixWr9Z1NFH46NMmfv4=; b=Q31gWePe1aiy4SUNL6x5xXqH636PzQxyayoxjnt22bY6Y255RH4IKkxv8x+IFlV77N3COI fPrCiig1B1LET938kjHVYkB2V1kSU5jAVCo2kkAJ7k7PH4ALbm/+aupa8LOdcXUq3B/tM3 ShFMTg/8j6f1Kyo9l+3WmqW/royrxCY= X-MC-Unique: D55bB6I2OqW56sw30bozIA-1 X-Mimecast-MFC-AGG-ID: D55bB6I2OqW56sw30bozIA_1768297035 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Eric Auger , Yi Liu , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 11/41] intel_iommu_accel: Check for compatibility with IOMMUFD backed device when x-flts=on Date: Tue, 13 Jan 2026 10:36:07 +0100 Message-ID: <20260113093637.1549214-12-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297097630158500 From: Zhenzhong Duan When vIOMMU is configured x-flts=3Don in scalable mode, first stage page ta= ble is passed to host to construct nested page table for passthrough devices. We need to check compatibility of some critical IOMMU capabilities between vIOMMU and host IOMMU to ensure guest first stage page table could be used = by host. For instance, vIOMMU supports first stage 1GB large page mapping, but host = does not, then this IOMMUFD backed device should fail. Even of the checks pass, for now we willingly reject the association because all the bits are not there yet, it will be relaxed in the end of this serie= s. Note vIOMMU has exposed VIOMMU_FLAG_WANT_NESTING_PARENT flag to force VFIO core to create nesting parent HWPT, if host doesn't support nested translation, the creation will fail. So no need to check nested capability here. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-10-zhenzhong= .duan@intel.com [ clg: - hw/i386/intel_iommu_accel.[hc]: Changed Copyright date 2025 -> 2026 - in commit log : IOMMU_HWPT_ALLOC_NEST_PARENT -> VIOMMU_FLAG_WANT_NESTING_PARENT ] Signed-off-by: C=C3=A9dric Le Goater --- MAINTAINERS | 1 + hw/i386/intel_iommu_accel.h | 28 +++++++++++++++++++++++++ hw/i386/intel_iommu.c | 5 ++--- hw/i386/intel_iommu_accel.c | 42 +++++++++++++++++++++++++++++++++++++ hw/i386/Kconfig | 5 +++++ hw/i386/meson.build | 1 + 6 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 hw/i386/intel_iommu_accel.h create mode 100644 hw/i386/intel_iommu_accel.c diff --git a/MAINTAINERS b/MAINTAINERS index 620b184aa5f91f8f86879cf22eabe720a9fa33a3..4ddbfba9f0118190b7dd3a3d640= 0e34774d5e17a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3961,6 +3961,7 @@ R: Cl=C3=A9ment Mathieu--Drif S: Supported F: hw/i386/intel_iommu.c F: hw/i386/intel_iommu_internal.h +F: hw/i386/intel_iommu_accel.* F: include/hw/i386/intel_iommu.h F: tests/functional/x86_64/test_intel_iommu.py F: tests/qtest/intel-iommu-test.c diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h new file mode 100644 index 0000000000000000000000000000000000000000..79117b25a030a3d22d75b635725= a6f78a21ec407 --- /dev/null +++ b/hw/i386/intel_iommu_accel.h @@ -0,0 +1,28 @@ +/* + * Intel IOMMU acceleration with nested translation + * + * Copyright (C) 2026 Intel Corporation. + * + * Authors: Zhenzhong Duan + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_I386_INTEL_IOMMU_ACCEL_H +#define HW_I386_INTEL_IOMMU_ACCEL_H +#include CONFIG_DEVICES + +#ifdef CONFIG_VTD_ACCEL +bool vtd_check_hiod_accel(IntelIOMMUState *s, HostIOMMUDevice *hiod, + Error **errp); +#else +static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, + HostIOMMUDevice *hiod, + Error **errp) +{ + error_setg(errp, "host IOMMU cannot be checked!"); + error_append_hint(errp, "CONFIG_VTD_ACCEL is not enabled"); + return false; +} +#endif +#endif diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 3a3725e489595121b1fdb0f38a1e85fa7f64c1f6..b11798d4b75b7fb6961a1b2bde8= 851667b0d07db 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -26,6 +26,7 @@ #include "hw/core/sysbus.h" #include "hw/core/iommu.h" #include "intel_iommu_internal.h" +#include "intel_iommu_accel.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" #include "hw/core/qdev-properties.h" @@ -4595,9 +4596,7 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIO= MMUDevice *hiod, return true; } =20 - error_setg(errp, - "host device is uncompatible with first stage translation"); - return false; + return vtd_check_hiod_accel(s, hiod, errp); } =20 static bool vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn, diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c new file mode 100644 index 0000000000000000000000000000000000000000..2942eff100b9e7871326d27b58b= 71517ff705271 --- /dev/null +++ b/hw/i386/intel_iommu_accel.c @@ -0,0 +1,42 @@ +/* + * Intel IOMMU acceleration with nested translation + * + * Copyright (C) 2026 Intel Corporation. + * + * Authors: Zhenzhong Duan + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "system/iommufd.h" +#include "intel_iommu_internal.h" +#include "intel_iommu_accel.h" + +bool vtd_check_hiod_accel(IntelIOMMUState *s, HostIOMMUDevice *hiod, + Error **errp) +{ + struct HostIOMMUDeviceCaps *caps =3D &hiod->caps; + struct iommu_hw_info_vtd *vtd =3D &caps->vendor_caps.vtd; + + if (!object_dynamic_cast(OBJECT(hiod), TYPE_HOST_IOMMU_DEVICE_IOMMUFD)= ) { + error_setg(errp, "Need IOMMUFD backend when x-flts=3Don"); + return false; + } + + if (caps->type !=3D IOMMU_HW_INFO_TYPE_INTEL_VTD) { + error_setg(errp, "Incompatible host platform IOMMU type %d", + caps->type); + return false; + } + + if (s->fs1gp && !(vtd->cap_reg & VTD_CAP_FS1GP)) { + error_setg(errp, + "First stage 1GB large page is unsupported by host IOMM= U"); + return false; + } + + error_setg(errp, + "host IOMMU is incompatible with guest first stage translat= ion"); + return false; +} diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index 6a0ab54bea4ab8599965a7b4dec60194f85877cb..12473acaa7344c36f6bf20eadd0= 58d414dc6f945 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -150,8 +150,13 @@ config X86_IOMMU =20 config VTD bool + imply VTD_ACCEL select X86_IOMMU =20 +config VTD_ACCEL + bool + depends on VTD && IOMMUFD + config AMD_IOMMU bool select X86_IOMMU diff --git a/hw/i386/meson.build b/hw/i386/meson.build index 436b3ce52d6480457a84c796ee5ed79e3a0bec36..63ae57baa511e6e29b0e6a27635= 2cd61df6602a6 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -21,6 +21,7 @@ i386_ss.add(when: 'CONFIG_Q35', if_true: files('pc_q35.c'= )) i386_ss.add(when: 'CONFIG_VMMOUSE', if_true: files('vmmouse.c')) i386_ss.add(when: 'CONFIG_VMPORT', if_true: files('vmport.c')) i386_ss.add(when: 'CONFIG_VTD', if_true: files('intel_iommu.c')) +i386_ss.add(when: 'CONFIG_VTD_ACCEL', if_true: files('intel_iommu_accel.c'= )) i386_ss.add(when: 'CONFIG_SGX', if_true: files('sgx-epc.c','sgx.c'), if_false: files('sgx-stub.c')) =20 --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297076; cv=none; d=zohomail.com; s=zohoarc; b=P4wBUYak9TOltvVh7GofBLHwBkCtojuD/dVoKI285P5WxKJwsAzgGHusBTJYE2azTORnnd5qCMi4hOLWnx3/zKspxW1PR6jNPRGhphHgjpwj2yZARmER92EJIM6QN3VK32YB4lKRa4mFpL9iloMzPiWiWo1Q2ILsa69/WnipGQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297076; 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=LLSaEL8hFLNBJUbpGN52yDV/UnUeDG0ybE+dW81ZIPs=; b=cv81ILWdDd7+g2NcvoXl0BD+GhD0PRuxPse/3LDbDwSOwGw5jwhMVU2OWhj/I0cMie9y4FlOMeuBGT6qWlrM+ngJwu1EkyVJC3qQkCHrqKOp/Rfr7OqZ++k/tidhshu0q+Cj2zVRWJb9AwUbcVmzqKbAanXhtkdGqd98jC8LG78= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297076123416.613068522445; Tue, 13 Jan 2026 01:37:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaq6-0007Sv-Mn; Tue, 13 Jan 2026 04:37:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaq4-0007Gl-Fu for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaq2-0003KA-Pb for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:24 -0500 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-103-8QTTzXDAN3-NvFgSOY7Bsg-1; Tue, 13 Jan 2026 04:37:18 -0500 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 A73AB1956050; Tue, 13 Jan 2026 09:37:17 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 76FBF30001A8; Tue, 13 Jan 2026 09:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297042; 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=LLSaEL8hFLNBJUbpGN52yDV/UnUeDG0ybE+dW81ZIPs=; b=RVrJ1/1Rgv0feRjWTXM0s1RTZz3D+hcqql4nPeUN99yuC5Mn7UUGVIx9EURuFBWbkizTOZ fNDYV+F6LAIUV+H5cX8alTC1n53E7jmLt5r20fM+tkchkW5A/7K5WCQ05WZj8ad0L/DWxF 2xrVqM8aLpPIkwRaWyAHsAVEC//cMGk= X-MC-Unique: 8QTTzXDAN3-NvFgSOY7Bsg-1 X-Mimecast-MFC-AGG-ID: 8QTTzXDAN3-NvFgSOY7Bsg_1768297037 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , Eric Auger , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 12/41] intel_iommu_accel: Fail passthrough device under PCI bridge if x-flts=on Date: Tue, 13 Jan 2026 10:36:08 +0100 Message-ID: <20260113093637.1549214-13-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297077642158500 From: Zhenzhong Duan Currently we don't support nested translation for passthrough device with emulated device under same PCI bridge, because they require different addre= ss space when x-flts=3Don. In theory, we do support if devices under same PCI bridge are all passthrou= gh devices. But emulated device can be hotplugged under same bridge. To simpli= fy, just forbid passthrough device under PCI bridge no matter if there is, or w= ill be emulated devices under same bridge. This is acceptable because PCIE brid= ge is more popular than PCI bridge now. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-11-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_accel.h | 4 ++-- hw/i386/intel_iommu.c | 7 ++++--- hw/i386/intel_iommu_accel.c | 12 +++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 79117b25a030a3d22d75b635725a6f78a21ec407..1d1fffb731a0daaf81f283e9967= 07b25738eb5b6 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -13,11 +13,11 @@ #include CONFIG_DEVICES =20 #ifdef CONFIG_VTD_ACCEL -bool vtd_check_hiod_accel(IntelIOMMUState *s, HostIOMMUDevice *hiod, +bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, - HostIOMMUDevice *hiod, + VTDHostIOMMUDevice *vtd_hiod, Error **errp) { error_setg(errp, "host IOMMU cannot be checked!"); diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index b11798d4b75b7fb6961a1b2bde8851667b0d07db..0817b1777220072f6b10e13af73= b1c6434447d1a 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4570,9 +4570,10 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s,= PCIBus *bus, return vtd_dev_as; } =20 -static bool vtd_check_hiod(IntelIOMMUState *s, HostIOMMUDevice *hiod, +static bool vtd_check_hiod(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hio= d, Error **errp) { + HostIOMMUDevice *hiod =3D vtd_hiod->hiod; HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_GET_CLASS(hiod); int ret; =20 @@ -4596,7 +4597,7 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostIO= MMUDevice *hiod, return true; } =20 - return vtd_check_hiod_accel(s, hiod, errp); + return vtd_check_hiod_accel(s, vtd_hiod, errp); } =20 static bool vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn, @@ -4632,7 +4633,7 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, voi= d *opaque, int devfn, vtd_hiod->iommu_state =3D s; vtd_hiod->hiod =3D hiod; =20 - if (!vtd_check_hiod(s, hiod, errp)) { + if (!vtd_check_hiod(s, vtd_hiod, errp)) { g_free(vtd_hiod); vtd_iommu_unlock(s); return false; diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 2942eff100b9e7871326d27b58b71517ff705271..99f173b2486c4bd05d6cfeed56d= 03c3efc6a658d 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -12,12 +12,16 @@ #include "system/iommufd.h" #include "intel_iommu_internal.h" #include "intel_iommu_accel.h" +#include "hw/pci/pci_bus.h" =20 -bool vtd_check_hiod_accel(IntelIOMMUState *s, HostIOMMUDevice *hiod, +bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp) { + HostIOMMUDevice *hiod =3D vtd_hiod->hiod; struct HostIOMMUDeviceCaps *caps =3D &hiod->caps; struct iommu_hw_info_vtd *vtd =3D &caps->vendor_caps.vtd; + PCIBus *bus =3D vtd_hiod->bus; + PCIDevice *pdev =3D bus->devices[vtd_hiod->devfn]; =20 if (!object_dynamic_cast(OBJECT(hiod), TYPE_HOST_IOMMU_DEVICE_IOMMUFD)= ) { error_setg(errp, "Need IOMMUFD backend when x-flts=3Don"); @@ -36,6 +40,12 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, HostIOMMUD= evice *hiod, return false; } =20 + if (pci_device_get_iommu_bus_devfn(pdev, &bus, NULL, NULL)) { + error_setg(errp, "Host device downstream to a PCI bridge is " + "unsupported when x-flts=3Don"); + return false; + } + error_setg(errp, "host IOMMU is incompatible with guest first stage translat= ion"); return false; --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297300; cv=none; d=zohomail.com; s=zohoarc; b=Tf/A8tXzf4+i9TiUDcotYYExu+1WgdepYE/R28p+YLRe+Td6eWvR9on5KeIJrYXTP16cTDrEFRsU6Fv712NStzrItRQ7YDVf0QCyyzkA/ubHTCX6lw81PmV3zQ7W/bwGOSCNSkwDg01VZOL9P2ZUDDwQSE4wyhqzYpsXAoL00wA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297300; 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=Rh+r0MErbom7aUEI17w5YTrlgY2yEdWfy4ic/bfvkHA=; b=b/iKsv84S8VWAF6DUp2fpy734sumz+7P/ql+PXFUFRjCZnbYOp30Tx+OUfs6qDlThT1Uxhg3xGa7nQKMvIsI62JaHOhA8nGHonKtBBdNkOFP+23vL2fuLiT6NeVBIC0CYqD3B7nXqOBEsD6M+90Zpn05dirZa/LxXY8HIwlif5I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297300721931.5617881810822; Tue, 13 Jan 2026 01:41:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqH-00086d-R4; Tue, 13 Jan 2026 04:37:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqF-0007qB-EO for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqD-0003Ll-Pr for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:35 -0500 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-608-8ThEKYj_Omeyx51BNMarqQ-1; Tue, 13 Jan 2026 04:37:25 -0500 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 57FA6195605B; Tue, 13 Jan 2026 09:37:20 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 25D0630001A2; Tue, 13 Jan 2026 09:37:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297053; 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=Rh+r0MErbom7aUEI17w5YTrlgY2yEdWfy4ic/bfvkHA=; b=aolIsNMukIKl6TCuLf2VCWXieTfgepMDCKg07PztnVr5rOiDtwSna/iGYHIbZp2A5SnyLJ 3ItU6R5xrF/H2vZ2okcUMUGzOhSFk4LQGEqJXuEQEIDmImmaSyl6aHq+V2dTVC06FiM0Ug 2F5MBF/uCUlBAqLwYG8qys2U0OPZuJo= X-MC-Unique: 8ThEKYj_Omeyx51BNMarqQ-1 X-Mimecast-MFC-AGG-ID: 8ThEKYj_Omeyx51BNMarqQ_1768297044 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , Eric Auger , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 13/41] intel_iommu_accel: Stick to system MR for IOMMUFD backed host device when x-flts=on Date: Tue, 13 Jan 2026 10:36:09 +0100 Message-ID: <20260113093637.1549214-14-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297302392158500 From: Zhenzhong Duan When guest enables scalable mode and setup first stage page table, we don't want to use IOMMU MR but rather continue using the system MR for IOMMUFD backed host device. Then default HWPT in VFIO contains GPA->HPA mappings which could be reused as nesting parent HWPT to construct nested HWPT in vIOMMU. Move vtd_as_key into intel_iommu_internal.h as it's also used by accel code. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-12-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_accel.h | 6 ++++++ hw/i386/intel_iommu_internal.h | 11 +++++++++++ hw/i386/intel_iommu.c | 28 +++++++++++++++------------- hw/i386/intel_iommu_accel.c | 18 ++++++++++++++++++ 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 1d1fffb731a0daaf81f283e996707b25738eb5b6..9558148c517bd9c46e95e49c188= 4152f6c370799 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -15,6 +15,7 @@ #ifdef CONFIG_VTD_ACCEL bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp); +VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, @@ -24,5 +25,10 @@ static inline bool vtd_check_hiod_accel(IntelIOMMUState = *s, error_append_hint(errp, "CONFIG_VTD_ACCEL is not enabled"); return false; } + +static inline VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *a= s) +{ + return NULL; +} #endif #endif diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 02522f64e0796dfcb40945e62961d60be24a98ae..d8dad183043798d7c052a5b0767= ab662ef3e9960 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -685,4 +685,15 @@ typedef struct VTDHostIOMMUDevice { uint8_t devfn; HostIOMMUDevice *hiod; } VTDHostIOMMUDevice; + +/* + * PCI bus number (or SID) is not reliable since the device is usaully + * initialized before guest can configure the PCI bridge + * (SECONDARY_BUS_NUMBER). + */ +struct vtd_as_key { + PCIBus *bus; + uint8_t devfn; + uint32_t pasid; +}; #endif diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 0817b1777220072f6b10e13af73b1c6434447d1a..d5a4e02fa1138e0195b6ac22551= 2dafe041e0605 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -55,17 +55,6 @@ #define VTD_PE_GET_SS_LEVEL(pe) \ (2 + (((pe)->val[0] >> 2) & VTD_SM_PASID_ENTRY_AW)) =20 -/* - * PCI bus number (or SID) is not reliable since the device is usaully - * initialized before guest can configure the PCI bridge - * (SECONDARY_BUS_NUMBER). - */ -struct vtd_as_key { - PCIBus *bus; - uint8_t devfn; - uint32_t pasid; -}; - /* bus/devfn is PCI device's real BDF not the aliased one */ struct vtd_hiod_key { PCIBus *bus; @@ -1730,12 +1719,25 @@ static bool vtd_as_pt_enabled(VTDAddressSpace *as) /* Return whether the device is using IOMMU translation. */ static bool vtd_switch_address_space(VTDAddressSpace *as) { + IntelIOMMUState *s; bool use_iommu, pt; =20 assert(as); =20 - use_iommu =3D as->iommu_state->dmar_enabled && !vtd_as_pt_enabled(as); - pt =3D as->iommu_state->dmar_enabled && vtd_as_pt_enabled(as); + s =3D as->iommu_state; + use_iommu =3D s->dmar_enabled && !vtd_as_pt_enabled(as); + pt =3D s->dmar_enabled && vtd_as_pt_enabled(as); + + /* + * When guest enables scalable mode and sets up first stage page table, + * we stick to system MR for IOMMUFD backed host device. Then its + * default hwpt contains GPA->HPA mappings which is used directly if + * PGTT=3DPT and used as nesting parent if PGTT=3DFST. Otherwise fall = back + * to original processing. + */ + if (s->root_scalable && s->fsts && vtd_find_hiod_iommufd(as)) { + use_iommu =3D false; + } =20 trace_vtd_switch_address_space(pci_bus_num(as->bus), VTD_PCI_SLOT(as->devfn), diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 99f173b2486c4bd05d6cfeed56d03c3efc6a658d..acc9cad959ef2e00f5b2783ea39= 75a91493d0521 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -50,3 +50,21 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOM= MUDevice *vtd_hiod, "host IOMMU is incompatible with guest first stage translat= ion"); return false; } + +VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as) +{ + IntelIOMMUState *s =3D as->iommu_state; + struct vtd_as_key key =3D { + .bus =3D as->bus, + .devfn =3D as->devfn, + }; + VTDHostIOMMUDevice *vtd_hiod =3D g_hash_table_lookup(s->vtd_host_iommu= _dev, + &key); + + if (vtd_hiod && vtd_hiod->hiod && + object_dynamic_cast(OBJECT(vtd_hiod->hiod), + TYPE_HOST_IOMMU_DEVICE_IOMMUFD)) { + return vtd_hiod; + } + return NULL; +} --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297087; cv=none; d=zohomail.com; s=zohoarc; b=knll3BcFL14G2rR1u3qEkWgrq4y9SPRMKCQzlaG2eZjzy8ueMukkQ9yJeR5NCqDCOQvo1vUkWaQFFZHTuY7LFcLfcrDsB/M2EkKa8wFjlJhY/FzvHA+IW5ZQu4qfVwKl2Z0PFhSEtAzjONFqrXRGW80fAi26HFa/DblJJ2oQV68= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297087; 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=mv0EwYzlFCvikSoABPO1ryNNzeN1Wj7ju0V4ba1YJwM=; b=Ecpk0P27Ued1Vs0PWouEmoqGanZZsGn4GO6r5NNDpARpxCyQvFM7ndXZUNvZs568n00ZOYIhmOK/HoV437ks/V8aaNamJ+o1DyAB7SB5cd15XCOGLOwDM6E2Xxz1oMJYAzG6TflIZ84vg7xjJ0MHyWCzLY7zfocepgE2cD6hy5k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297087947300.69830781690223; Tue, 13 Jan 2026 01:38:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqC-0007cW-67; Tue, 13 Jan 2026 04:37:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqA-0007bE-Ix for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaq8-0003Kr-Ii for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:30 -0500 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-656-spmEiJ6IO1m3vWU7A9aaPw-1; Tue, 13 Jan 2026 04:37:24 -0500 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 23442195608F; Tue, 13 Jan 2026 09:37:23 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C6AE230001A2; Tue, 13 Jan 2026 09:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297047; 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=mv0EwYzlFCvikSoABPO1ryNNzeN1Wj7ju0V4ba1YJwM=; b=LuT4AD0dVZy7JB4TKT5xpy/iZLM5c1yXHr/frfALRgqhpH5T10phDY7TEl8UJMBa4p/NHd T5oxlbrBuaSlZrhdjSrk6lgs09nVgEq6P/IIPFmMpCvRYpb1ZcRlxTcPMTqcICrunQJCrD I0OYq3nIO48Mp6cXPqBfBFgc6yTlQbQ= X-MC-Unique: spmEiJ6IO1m3vWU7A9aaPw-1 X-Mimecast-MFC-AGG-ID: spmEiJ6IO1m3vWU7A9aaPw_1768297043 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Eric Auger , Yi Liu , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 14/41] intel_iommu: Add some macros and inline functions Date: Tue, 13 Jan 2026 10:36:10 +0100 Message-ID: <20260113093637.1549214-15-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297089625158500 From: Zhenzhong Duan Add some macros and inline functions that will be used by following patch. This patch also make a cleanup to change below macros to use extract64() just like what smmu does, because they are either used in following patches or used indirectly by new introduced inline functions. VTD_INV_DESC_PIOTLB_IH VTD_SM_PASID_ENTRY_PGTT VTD_SM_PASID_ENTRY_DID VTD_SM_PASID_ENTRY_FSPM VTD_SM_PASID_ENTRY_FSPTPTR But we doesn't aim to change the huge amount of bit mask style macro definitions in this patch, that should be in a separate patch. Suggested-by: Eric Auger Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu Reviewed-by: Eric Auger Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-13-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_internal.h | 50 ++++++++++++++++++++++++++++------ hw/i386/intel_iommu.c | 27 +++++++++--------- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index d8dad183043798d7c052a5b0767ab662ef3e9960..e987322e93ab05db2873d550de7= 8abca268ca8c9 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -516,7 +516,7 @@ typedef union VTDPRDesc VTDPRDesc; #define VTD_INV_DESC_PIOTLB_DID(val) (((val) >> 16) & VTD_DOMAIN_ID_M= ASK) #define VTD_INV_DESC_PIOTLB_PASID(val) (((val) >> 32) & 0xfffffULL) #define VTD_INV_DESC_PIOTLB_AM(val) ((val) & 0x3fULL) -#define VTD_INV_DESC_PIOTLB_IH(val) (((val) >> 6) & 0x1) +#define VTD_INV_DESC_PIOTLB_IH(x) extract64((x)->val[1], 6, 1) #define VTD_INV_DESC_PIOTLB_ADDR(val) ((val) & ~0xfffULL) #define VTD_INV_DESC_PIOTLB_RSVD_VAL0 0xfff000000000f1c0ULL #define VTD_INV_DESC_PIOTLB_RSVD_VAL1 0xf80ULL @@ -636,17 +636,20 @@ typedef struct VTDPASIDCacheInfo { =20 /* PASID Granular Translation Type Mask */ #define VTD_PASID_ENTRY_P 1ULL -#define VTD_SM_PASID_ENTRY_PGTT (7ULL << 6) -#define VTD_SM_PASID_ENTRY_FST (1ULL << 6) -#define VTD_SM_PASID_ENTRY_SST (2ULL << 6) -#define VTD_SM_PASID_ENTRY_NESTED (3ULL << 6) -#define VTD_SM_PASID_ENTRY_PT (4ULL << 6) +#define VTD_SM_PASID_ENTRY_PGTT(x) extract64((x)->val[0], 6, 3) +#define VTD_SM_PASID_ENTRY_FST 1 +#define VTD_SM_PASID_ENTRY_SST 2 +#define VTD_SM_PASID_ENTRY_NESTED 3 +#define VTD_SM_PASID_ENTRY_PT 4 =20 #define VTD_SM_PASID_ENTRY_AW 7ULL /* Adjusted guest-address-widt= h */ -#define VTD_SM_PASID_ENTRY_DID(val) ((val) & VTD_DOMAIN_ID_MASK) +#define VTD_SM_PASID_ENTRY_DID(x) extract64((x)->val[1], 0, 16) =20 -#define VTD_SM_PASID_ENTRY_FSPM 3ULL -#define VTD_SM_PASID_ENTRY_FSPTPTR (~0xfffULL) +#define VTD_SM_PASID_ENTRY_SRE(x) extract64((x)->val[2], 0, 1) +#define VTD_SM_PASID_ENTRY_FSPM(x) extract64((x)->val[2], 2, 2) +#define VTD_SM_PASID_ENTRY_WPE(x) extract64((x)->val[2], 4, 1) +#define VTD_SM_PASID_ENTRY_EAFE(x) extract64((x)->val[2], 7, 1) +#define VTD_SM_PASID_ENTRY_FSPTPFN(x) extract64((x)->val[2], 12, 52) =20 /* First Stage Paging Structure */ /* Masks for First Stage Paging Entry */ @@ -696,4 +699,33 @@ struct vtd_as_key { uint8_t devfn; uint32_t pasid; }; + +static inline dma_addr_t vtd_pe_get_fspt_base(VTDPASIDEntry *pe) +{ + return VTD_SM_PASID_ENTRY_FSPTPFN(pe) << VTD_PAGE_SHIFT; +} + +/* + * First stage IOVA address width: 48 bits for 4-level paging(FSPM=3D00) + * 57 bits for 5-level paging(FSPM=3D01) + */ +static inline uint32_t vtd_pe_get_fs_aw(VTDPASIDEntry *pe) +{ + /* + * Paging mode for first-stage translation (VTD spec Figure 9-6) + * 00: 4-level paging, 01: 5-level paging + */ + return VTD_HOST_AW_48BIT + VTD_SM_PASID_ENTRY_FSPM(pe) * 9; +} + +static inline bool vtd_pe_pgtt_is_pt(VTDPASIDEntry *pe) +{ + return (VTD_SM_PASID_ENTRY_PGTT(pe) =3D=3D VTD_SM_PASID_ENTRY_PT); +} + +/* check if PGTT is first stage translation */ +static inline bool vtd_pe_pgtt_is_fst(VTDPASIDEntry *pe) +{ + return (VTD_SM_PASID_ENTRY_PGTT(pe) =3D=3D VTD_SM_PASID_ENTRY_FST); +} #endif diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index d5a4e02fa1138e0195b6ac225512dafe041e0605..9edd625b1a5d246c311efd510df= 3967749690c29 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -48,10 +48,11 @@ #define VTD_CE_GET_PRE(ce) \ ((ce)->val[0] & VTD_SM_CONTEXT_ENTRY_PRE) =20 -/* pe operations */ -#define VTD_PE_GET_TYPE(pe) ((pe)->val[0] & VTD_SM_PASID_ENTRY_PGTT) -#define VTD_PE_GET_FS_LEVEL(pe) \ - (4 + (((pe)->val[2] >> 2) & VTD_SM_PASID_ENTRY_FSPM)) +/* + * Paging mode for first-stage translation (VTD spec Figure 9-6) + * 00: 4-level paging, 01: 5-level paging + */ +#define VTD_PE_GET_FS_LEVEL(pe) (VTD_SM_PASID_ENTRY_FSPM(pe) + 4) #define VTD_PE_GET_SS_LEVEL(pe) \ (2 + (((pe)->val[0] >> 2) & VTD_SM_PASID_ENTRY_AW)) =20 @@ -807,7 +808,7 @@ static inline bool vtd_is_fs_level_supported(IntelIOMMU= State *s, uint32_t level) /* Return true if check passed, otherwise false */ static inline bool vtd_pe_type_check(IntelIOMMUState *s, VTDPASIDEntry *pe) { - switch (VTD_PE_GET_TYPE(pe)) { + switch (VTD_SM_PASID_ENTRY_PGTT(pe)) { case VTD_SM_PASID_ENTRY_FST: return !!(s->ecap & VTD_ECAP_FSTS); case VTD_SM_PASID_ENTRY_SST: @@ -882,7 +883,7 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUSta= te *s, return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 - pgtt =3D VTD_PE_GET_TYPE(pe); + pgtt =3D VTD_SM_PASID_ENTRY_PGTT(pe); if (pgtt =3D=3D VTD_SM_PASID_ENTRY_SST && !vtd_is_ss_level_supported(s, VTD_PE_GET_SS_LEVEL(pe))) { return -VTD_FR_PASID_TABLE_ENTRY_INV; @@ -1116,7 +1117,7 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUS= tate *s, if (s->root_scalable) { vtd_ce_get_pasid_entry(s, ce, &pe, pasid); if (s->fsts) { - return pe.val[2] & VTD_SM_PASID_ENTRY_FSPTPTR; + return vtd_pe_get_fspt_base(&pe); } else { return pe.val[0] & VTD_SM_PASID_ENTRY_SSPTPTR; } @@ -1605,7 +1606,7 @@ static uint16_t vtd_get_domain_id(IntelIOMMUState *s, =20 if (s->root_scalable) { vtd_ce_get_pasid_entry(s, ce, &pe, pasid); - return VTD_SM_PASID_ENTRY_DID(pe.val[1]); + return VTD_SM_PASID_ENTRY_DID(&pe); } =20 return VTD_CONTEXT_ENTRY_DID(ce->hi); @@ -1687,7 +1688,7 @@ static bool vtd_dev_pt_enabled(IntelIOMMUState *s, VT= DContextEntry *ce, */ return false; } - return (VTD_PE_GET_TYPE(&pe) =3D=3D VTD_SM_PASID_ENTRY_PT); + return vtd_pe_pgtt_is_pt(&pe); } =20 return (vtd_ce_get_type(ce) =3D=3D VTD_CONTEXT_TT_PASS_THROUGH); @@ -3108,9 +3109,9 @@ static void vtd_pasid_cache_sync_locked(gpointer key,= gpointer value, /* Fall through */ case VTD_INV_DESC_PASIDC_G_DSI: if (pc_entry->valid) { - did =3D VTD_SM_PASID_ENTRY_DID(pc_entry->pasid_entry.val[1]); + did =3D VTD_SM_PASID_ENTRY_DID(&pc_entry->pasid_entry); } else { - did =3D VTD_SM_PASID_ENTRY_DID(pe.val[1]); + did =3D VTD_SM_PASID_ENTRY_DID(&pe); } if (pc_info->did !=3D did) { return; @@ -5154,8 +5155,8 @@ static int vtd_pri_perform_implicit_invalidation(VTDA= ddressSpace *vtd_as, if (ret) { return -EINVAL; } - pgtt =3D VTD_PE_GET_TYPE(&pe); - domain_id =3D VTD_SM_PASID_ENTRY_DID(pe.val[1]); + pgtt =3D VTD_SM_PASID_ENTRY_PGTT(&pe); + domain_id =3D VTD_SM_PASID_ENTRY_DID(&pe); ret =3D 0; switch (pgtt) { case VTD_SM_PASID_ENTRY_FST: --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297112; cv=none; d=zohomail.com; s=zohoarc; b=Ix9YeYNQhC4B5HJQDA4CuFjq9rlqA1geE6FGtvwT06zkZOpDla4SmW2KrNc9c6ZOlBxI/Poau7FhCmpJWLnpApjHdFCYEy8oXLWBjZ/CNkXHevsm1Yrnh8cHWMP5TU1uj8/u0NPwDYmrpKn86WeWk0OsmgAVCXRxy4cuZdm4p8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297112; 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=zkgUI30UqNpEWdfbXel2rGa7YE71POmVLIyhPMvMxgc=; b=WGdoHt3AeXgDFVqyKvcn2qaL27QQcA2kODZxvMqncjKmLoOoaHU3Zr97Rd0CZK+y2z8gBRKiPpO+ebuS46xVeP8utpt0J3Obcsb3xB8Yrq/6CCd/43So/ErytPAAGeArECsJt0WkVI5QKASDeVR2hRJZ3uaxO/iduN3cNx9CzrQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297112928169.67488057416392; Tue, 13 Jan 2026 01:38:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqF-0007pd-DW; Tue, 13 Jan 2026 04:37:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqD-0007jA-R1 for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqB-0003LO-LS for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:33 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-7-zfJBgum2OS-g29sPBbQw6A-1; Tue, 13 Jan 2026 04:37:27 -0500 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A1A471800371; Tue, 13 Jan 2026 09:37:26 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 931F130001A8; Tue, 13 Jan 2026 09:37:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297051; 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=zkgUI30UqNpEWdfbXel2rGa7YE71POmVLIyhPMvMxgc=; b=cErR34Q2PbmGohY1TLsdK6SM8nS3IJ2md4K9EQ+UL5d3Gx5QT+jGgL06twuQ4NsHRLI4mx kQRYHj5lpc5YSm3wll1OhZvCNVkvwYJXaXWQsQI0aLejanCf0TFeMAnV9zkKqkivsdVyuD ZURvLalSTwlUDbLnzQL+bRoavBIBRr0= X-MC-Unique: zfJBgum2OS-g29sPBbQw6A-1 X-Mimecast-MFC-AGG-ID: zfJBgum2OS-g29sPBbQw6A_1768297046 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , Yi Sun , Eric Auger , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 15/41] intel_iommu_accel: Bind/unbind guest page table to host Date: Tue, 13 Jan 2026 10:36:11 +0100 Message-ID: <20260113093637.1549214-16-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297113734158500 From: Zhenzhong Duan This captures the guest PASID table entry modifications and propagates the changes to host to attach a hwpt with type determined per guest IOMMU PGTT configuration. When PGTT=3DPT, attach PASID_0 to a second stage HWPT(GPA->HPA). When PGTT=3DFST, attach PASID_0 to nested HWPT with nesting parent HWPT coming from VFIO. Co-Authored-by: Yi Liu Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-14-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_accel.h | 7 +++ include/hw/i386/intel_iommu.h | 2 + hw/i386/intel_iommu.c | 22 ++++++- hw/i386/intel_iommu_accel.c | 114 ++++++++++++++++++++++++++++++++++ hw/i386/trace-events | 3 + 5 files changed, 145 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 9558148c517bd9c46e95e49c1884152f6c370799..30696765af61b8864b3577984c5= d9bcd774d4212 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -16,6 +16,7 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp); VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as); +bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, Error **errp); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, @@ -30,5 +31,11 @@ static inline VTDHostIOMMUDevice *vtd_find_hiod_iommufd(= VTDAddressSpace *as) { return NULL; } + +static inline bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, + Error **errp) +{ + return true; +} #endif #endif diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 401322665ac8e1a25330825b9e506d3942249c92..6c61fd39c7bb737afaca47ef792= 1ee96a9e6e473 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -154,6 +154,8 @@ struct VTDAddressSpace { * with the guest IOMMU pgtables for a device. */ IOVATree *iova_tree; + + uint32_t fs_hwpt_id; }; =20 struct VTDIOTLBEntry { diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 9edd625b1a5d246c311efd510df3967749690c29..f9b80e3257b4e382fd0eb9f946f= 6b6691a3d09ab 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -87,7 +87,11 @@ static void vtd_pasid_cache_reset_locked(IntelIOMMUState= *s) g_hash_table_iter_init(&as_it, s->vtd_address_spaces); while (g_hash_table_iter_next(&as_it, NULL, (void **)&vtd_as)) { VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; - pc_entry->valid =3D false; + if (pc_entry->valid) { + pc_entry->valid =3D false; + /* It's fatal to get failure during reset */ + vtd_propagate_guest_pasid(vtd_as, &error_fatal); + } } } =20 @@ -3073,6 +3077,8 @@ static void vtd_pasid_cache_sync_locked(gpointer key,= gpointer value, VTDPASIDEntry pe; IOMMUNotifier *n; uint16_t did; + const char *err_prefix =3D "Attaching to HWPT failed: "; + Error *local_err =3D NULL; =20 if (vtd_dev_get_pe_from_pasid(vtd_as, &pe)) { if (!pc_entry->valid) { @@ -3093,7 +3099,9 @@ static void vtd_pasid_cache_sync_locked(gpointer key,= gpointer value, vtd_address_space_unmap(vtd_as, n); } vtd_switch_address_space(vtd_as); - return; + + err_prefix =3D "Detaching from HWPT failed: "; + goto do_bind_unbind; } =20 /* @@ -3121,12 +3129,20 @@ static void vtd_pasid_cache_sync_locked(gpointer ke= y, gpointer value, if (!pc_entry->valid) { pc_entry->pasid_entry =3D pe; pc_entry->valid =3D true; - } else if (!vtd_pasid_entry_compare(&pe, &pc_entry->pasid_entry)) { + } else if (vtd_pasid_entry_compare(&pe, &pc_entry->pasid_entry)) { + err_prefix =3D "Replacing HWPT attachment failed: "; + } else { return; } =20 vtd_switch_address_space(vtd_as); vtd_address_space_sync(vtd_as); + +do_bind_unbind: + /* TODO: Fault event injection into guest, report error to QEMU for no= w */ + if (!vtd_propagate_guest_pasid(vtd_as, &local_err)) { + error_reportf_err(local_err, "%s", err_prefix); + } } =20 static void vtd_pasid_cache_sync(IntelIOMMUState *s, VTDPASIDCacheInfo *pc= _info) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index acc9cad959ef2e00f5b2783ea3975a91493d0521..69f82e8831f5f834126b9aa1550= a6da8f2cc94c5 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -13,6 +13,7 @@ #include "intel_iommu_internal.h" #include "intel_iommu_accel.h" #include "hw/pci/pci_bus.h" +#include "trace.h" =20 bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp) @@ -68,3 +69,116 @@ VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpa= ce *as) } return NULL; } + +static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev, + VTDPASIDEntry *pe, uint32_t *fs_hwpt_id, + Error **errp) +{ + struct iommu_hwpt_vtd_s1 vtd =3D {}; + + vtd.flags =3D (VTD_SM_PASID_ENTRY_SRE(pe) ? IOMMU_VTD_S1_SRE : 0) | + (VTD_SM_PASID_ENTRY_WPE(pe) ? IOMMU_VTD_S1_WPE : 0) | + (VTD_SM_PASID_ENTRY_EAFE(pe) ? IOMMU_VTD_S1_EAFE : 0); + vtd.addr_width =3D vtd_pe_get_fs_aw(pe); + vtd.pgtbl_addr =3D (uint64_t)vtd_pe_get_fspt_base(pe); + + return iommufd_backend_alloc_hwpt(idev->iommufd, idev->devid, idev->hw= pt_id, + 0, IOMMU_HWPT_DATA_VTD_S1, sizeof(vt= d), + &vtd, fs_hwpt_id, errp); +} + +static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev, + VTDAddressSpace *vtd_as) +{ + if (!vtd_as->fs_hwpt_id) { + return; + } + iommufd_backend_free_id(idev->iommufd, vtd_as->fs_hwpt_id); + vtd_as->fs_hwpt_id =3D 0; +} + +static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod, + VTDAddressSpace *vtd_as, Error **err= p) +{ + HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->h= iod); + VTDPASIDEntry *pe =3D &vtd_as->pasid_cache_entry.pasid_entry; + uint32_t hwpt_id =3D idev->hwpt_id; + bool ret; + + /* + * We can get here only if flts=3Don, the supported PGTT is FST or PT. + * Catch invalid PGTT when processing invalidation request to avoid + * attaching to wrong hwpt. + */ + if (!vtd_pe_pgtt_is_fst(pe) && !vtd_pe_pgtt_is_pt(pe)) { + error_setg(errp, "Invalid PGTT type %d", + (uint8_t)VTD_SM_PASID_ENTRY_PGTT(pe)); + return false; + } + + if (vtd_pe_pgtt_is_fst(pe)) { + if (!vtd_create_fs_hwpt(idev, pe, &hwpt_id, errp)) { + return false; + } + } + + ret =3D host_iommu_device_iommufd_attach_hwpt(idev, hwpt_id, errp); + trace_vtd_device_attach_hwpt(idev->devid, vtd_as->pasid, hwpt_id, ret); + if (ret) { + /* Destroy old fs_hwpt if it's a replacement */ + vtd_destroy_old_fs_hwpt(idev, vtd_as); + if (vtd_pe_pgtt_is_fst(pe)) { + vtd_as->fs_hwpt_id =3D hwpt_id; + } + } else if (vtd_pe_pgtt_is_fst(pe)) { + iommufd_backend_free_id(idev->iommufd, hwpt_id); + } + + return ret; +} + +static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod, + VTDAddressSpace *vtd_as, Error **err= p) +{ + HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->h= iod); + IntelIOMMUState *s =3D vtd_as->iommu_state; + uint32_t pasid =3D vtd_as->pasid; + bool ret; + + if (s->dmar_enabled && s->root_scalable) { + ret =3D host_iommu_device_iommufd_detach_hwpt(idev, errp); + trace_vtd_device_detach_hwpt(idev->devid, pasid, ret); + } else { + /* + * If DMAR remapping is disabled or guest switches to legacy mode, + * we fallback to the default HWPT which contains shadow page tabl= e. + * So guest DMA could still work. + */ + ret =3D host_iommu_device_iommufd_attach_hwpt(idev, idev->hwpt_id,= errp); + trace_vtd_device_reattach_def_hwpt(idev->devid, pasid, idev->hwpt_= id, + ret); + } + + if (ret) { + vtd_destroy_old_fs_hwpt(idev, vtd_as); + } + + return ret; +} + +bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, Error **errp) +{ + VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; + VTDHostIOMMUDevice *vtd_hiod =3D vtd_find_hiod_iommufd(vtd_as); + + /* Ignore emulated device or legacy VFIO backed device */ + if (!vtd_as->iommu_state->fsts || !vtd_hiod) { + return true; + } + + if (pc_entry->valid) { + return vtd_device_attach_iommufd(vtd_hiod, vtd_as, errp); + } + + return vtd_device_detach_iommufd(vtd_hiod, vtd_as, errp); +} diff --git a/hw/i386/trace-events b/hw/i386/trace-events index b704f4f90c3db8ac84fb49d98237b60800b792c7..5a3ee1cf6418ba0713a716266e6= 62ced2e3027f0 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -73,6 +73,9 @@ vtd_warn_invalid_qi_tail(uint16_t tail) "tail 0x%"PRIx16 vtd_warn_ir_vector(uint16_t sid, int index, int vec, int target) "sid 0x%"= PRIx16" index %d vec %d (should be: %d)" vtd_warn_ir_trigger(uint16_t sid, int index, int trig, int target) "sid 0x= %"PRIx16" index %d trigger %d (should be: %d)" vtd_reset_exit(void) "" +vtd_device_attach_hwpt(uint32_t dev_id, uint32_t pasid, uint32_t hwpt_id, = int ret) "dev_id %d pasid %d hwpt_id %d, ret: %d" +vtd_device_detach_hwpt(uint32_t dev_id, uint32_t pasid, int ret) "dev_id %= d pasid %d ret: %d" +vtd_device_reattach_def_hwpt(uint32_t dev_id, uint32_t pasid, uint32_t hwp= t_id, int ret) "dev_id %d pasid %d hwpt_id %d, ret: %d" =20 # amd_iommu.c amdvi_evntlog_fail(uint64_t addr, uint32_t head) "error: fail to write at = addr 0x%"PRIx64" + offset 0x%"PRIx32 --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297092; cv=none; d=zohomail.com; s=zohoarc; b=VD+BWAAHikR7kpJC7ebmqz0MprOu7Hu5UvonOfB+jIo0eIiWr+3UHHg3c9ikrznZZryVrMzAeXhsDVk/BaDrfLzGiw7zJ0ImROpCctJT80KDtTwaz3BBVmwLFfSMQ6nDBKI49Uo+6SWVnks3/Tm2dUzi7lDF/qZ48dE+F4jqWOo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297092; 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=aiqr9r0qi090TiI98ZmR7YFL4F6SY/8exnQMPCE2VWs=; b=IKGUpQoXS8RHCAT4vIikfSf+/lVONDgI5csUnFreeELJ8TH2oBF9fE3HACmF1cljnZcFBNWtubzs+kZtCGdBuvuw1T6NaZ2xJkHH4VVWr0dvfMkCjcVjdG5Syc8cjtIEV5iIRKpk3/z5bE486ezYj1oBtqe/g0RPcVFl/HMEaKA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297092002248.70124393297192; Tue, 13 Jan 2026 01:38:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqJ-0008Fc-4F; Tue, 13 Jan 2026 04:37:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqG-0007yz-P3 for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqE-0003M2-KK for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:36 -0500 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-553-ZTx_7nbBMDSNOIHEfJEUJg-1; Tue, 13 Jan 2026 04:37:30 -0500 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 928431956096; Tue, 13 Jan 2026 09:37:29 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1E3FC30001A2; Tue, 13 Jan 2026 09:37:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297054; 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=aiqr9r0qi090TiI98ZmR7YFL4F6SY/8exnQMPCE2VWs=; b=bTGYZ4yfDjIOC097cBeVQ17KiOmpNnX4fO/RYQqMAi8W/t4lGUCxQRi0eS2duVXHJnIx4S DxsfLktNk6bzmyLRXPsipUtbYpnNAN3s97s26l74wLrp9bTlhn5uyyrYHT5gO3kKiacihx 34gacJnfFl91MF9xXv5aXRZYjFKfCHY= X-MC-Unique: ZTx_7nbBMDSNOIHEfJEUJg-1 X-Mimecast-MFC-AGG-ID: ZTx_7nbBMDSNOIHEfJEUJg_1768297049 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Yi Liu , Yi Sun , Zhenzhong Duan , Eric Auger , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 16/41] intel_iommu_accel: Propagate PASID-based iotlb invalidation to host Date: Tue, 13 Jan 2026 10:36:12 +0100 Message-ID: <20260113093637.1549214-17-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297093638158500 From: Yi Liu This traps the guest PASID-based iotlb invalidation request and propagate it to host. Intel VT-d 3.0 supports nested translation in PASID granularity. Guest SVA support could be implemented by configuring nested translation on specific pasid. This is also known as dual stage DMA translation. Under such configuration, guest owns the GVA->GPA translation which is configured as first stage page table on host side for a specific pasid, and host owns GPA->HPA translation. As guest owns first stage translation table, piotlb invalidation should be propagated to host since host IOMMU will cache first level page table related mappings during DMA address translation. Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-15-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_accel.h | 10 +++++ hw/i386/intel_iommu_internal.h | 6 +++ hw/i386/intel_iommu.c | 11 ++++-- hw/i386/intel_iommu_accel.c | 69 ++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 30696765af61b8864b3577984c5d9bcd774d4212..6dec8788f18d0196550b3d0047d= c5a5b29ed2c6b 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -17,6 +17,9 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMM= UDevice *vtd_hiod, Error **errp); VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as); bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, Error **errp); +void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_= id, + uint32_t pasid, hwaddr addr, + uint64_t npages, bool ih); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, @@ -37,5 +40,12 @@ static inline bool vtd_propagate_guest_pasid(VTDAddressS= pace *vtd_as, { return true; } + +static inline void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, + uint16_t domain_id, + uint32_t pasid, hwaddr= addr, + uint64_t npages, bool = ih) +{ +} #endif #endif diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index e987322e93ab05db2873d550de78abca268ca8c9..a2ca79f925c22928432e4ca7e23= 81c4f535fbdf0 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -622,6 +622,12 @@ typedef struct VTDPASIDCacheInfo { uint32_t pasid; } VTDPASIDCacheInfo; =20 +typedef struct VTDPIOTLBInvInfo { + uint16_t domain_id; + uint32_t pasid; + struct iommu_hwpt_vtd_s1_invalidate *inv_data; +} VTDPIOTLBInvInfo; + /* PASID Table Related Definitions */ #define VTD_PASID_DIR_BASE_ADDR_MASK (~0xfffULL) #define VTD_PASID_TABLE_BASE_ADDR_MASK (~0xfffULL) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index f9b80e3257b4e382fd0eb9f946f6b6691a3d09ab..2889c29102b1c487f760906e403= 8274491da1a44 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2967,6 +2967,8 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUSta= te *s, vtd_iommu_lock(s); g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_pasid, &info); + vtd_flush_host_piotlb_all_locked(s, domain_id, pasid, 0, (uint64_t)-1, + false); vtd_iommu_unlock(s); =20 QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) { @@ -2986,7 +2988,8 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUSta= te *s, } =20 static void vtd_piotlb_page_invalidate(IntelIOMMUState *s, uint16_t domain= _id, - uint32_t pasid, hwaddr addr, uint8_= t am) + uint32_t pasid, hwaddr addr, uint8_= t am, + bool ih) { VTDIOTLBPageInvInfo info; =20 @@ -2998,6 +3001,7 @@ static void vtd_piotlb_page_invalidate(IntelIOMMUStat= e *s, uint16_t domain_id, vtd_iommu_lock(s); g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_page_piotlb, &info); + vtd_flush_host_piotlb_all_locked(s, domain_id, pasid, addr, 1 << am, i= h); vtd_iommu_unlock(s); =20 vtd_iotlb_page_invalidate_notify(s, domain_id, addr, am, pasid); @@ -3029,7 +3033,8 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState *= s, case VTD_INV_DESC_PIOTLB_PSI_IN_PASID: am =3D VTD_INV_DESC_PIOTLB_AM(inv_desc->val[1]); addr =3D (hwaddr) VTD_INV_DESC_PIOTLB_ADDR(inv_desc->val[1]); - vtd_piotlb_page_invalidate(s, domain_id, pasid, addr, am); + vtd_piotlb_page_invalidate(s, domain_id, pasid, addr, am, + VTD_INV_DESC_PIOTLB_IH(inv_desc)); break; =20 default: @@ -5176,7 +5181,7 @@ static int vtd_pri_perform_implicit_invalidation(VTDA= ddressSpace *vtd_as, ret =3D 0; switch (pgtt) { case VTD_SM_PASID_ENTRY_FST: - vtd_piotlb_page_invalidate(s, domain_id, vtd_as->pasid, addr, 0); + vtd_piotlb_page_invalidate(s, domain_id, vtd_as->pasid, addr, 0, f= alse); break; /* Room for other pgtt values */ default: diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 69f82e8831f5f834126b9aa1550a6da8f2cc94c5..1f068005d8fa8b2161247e1e238= 6db5a60dbbdc5 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -182,3 +182,72 @@ bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as= , Error **errp) =20 return vtd_device_detach_iommufd(vtd_hiod, vtd_as, errp); } + +/* + * This function is a loop function for the s->vtd_address_spaces + * list with VTDPIOTLBInvInfo as execution filter. It propagates + * the piotlb invalidation to host. + */ +static void vtd_flush_host_piotlb_locked(gpointer key, gpointer value, + gpointer user_data) +{ + VTDPIOTLBInvInfo *piotlb_info =3D user_data; + VTDAddressSpace *vtd_as =3D value; + VTDHostIOMMUDevice *vtd_hiod =3D vtd_find_hiod_iommufd(vtd_as); + VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; + uint16_t did; + + if (!vtd_hiod) { + return; + } + + assert(vtd_as->pasid =3D=3D PCI_NO_PASID); + + /* Nothing to do if there is no first stage HWPT attached */ + if (!pc_entry->valid || + !vtd_pe_pgtt_is_fst(&pc_entry->pasid_entry)) { + return; + } + + did =3D VTD_SM_PASID_ENTRY_DID(&pc_entry->pasid_entry); + + if (piotlb_info->domain_id =3D=3D did && piotlb_info->pasid =3D=3D PAS= ID_0) { + HostIOMMUDeviceIOMMUFD *idev =3D + HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod); + uint32_t entry_num =3D 1; /* Only implement one request for simpli= city */ + Error *local_err =3D NULL; + struct iommu_hwpt_vtd_s1_invalidate *cache =3D piotlb_info->inv_da= ta; + + if (!iommufd_backend_invalidate_cache(idev->iommufd, vtd_as->fs_hw= pt_id, + IOMMU_HWPT_INVALIDATE_DATA_V= TD_S1, + sizeof(*cache), &entry_num, = cache, + &local_err)) { + /* Something wrong in kernel, but trying to continue */ + error_report_err(local_err); + } + } +} + +void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_= id, + uint32_t pasid, hwaddr addr, + uint64_t npages, bool ih) +{ + struct iommu_hwpt_vtd_s1_invalidate cache_info =3D { 0 }; + VTDPIOTLBInvInfo piotlb_info; + + cache_info.addr =3D addr; + cache_info.npages =3D npages; + cache_info.flags =3D ih ? IOMMU_VTD_INV_FLAGS_LEAF : 0; + + piotlb_info.domain_id =3D domain_id; + piotlb_info.pasid =3D pasid; + piotlb_info.inv_data =3D &cache_info; + + /* + * Go through each vtd_as instance in s->vtd_address_spaces, find out + * affected host devices which need host piotlb invalidation. Piotlb + * invalidation should check pasid cache per architecture point of vie= w. + */ + g_hash_table_foreach(s->vtd_address_spaces, + vtd_flush_host_piotlb_locked, &piotlb_info); +} --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297136; cv=none; d=zohomail.com; s=zohoarc; b=eucQpuFH+1YlwJCWL52nkcPn39nR085ywMN3/zM4sNhsqaPOXpwSlO/1KSsmEKz9RnFVm2oWOcy9IXCc5CZKPJfgTCImJ3bHwKOAyCY6b4VOJ95rIo+K2jMz30S9owTXZGbp9jZ4uTw8ODBP/IImC+teFX+UwXEpfC9dl7Cy/RI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297136; 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=R3A2dSjUHqywYaMxMHKJqD/aXpL3mUU9vIKAwjAUR7Y=; b=oEwFyqVA7wJIxh/BNeDf0kGD1dVsEbGYJHOmHyVutBALJvUuZUBRIgiPmXRVJfP+DvGAIZS42Iq6jd9HFD6GHpty3Lf0MMvqNWvqKEWRy7fZ0qdfuFzrPTUVvVOzsdCR5pqYf+E1uaOMkNqkG0m9YUO8Y8JrCTrlyZxhxlDHBcI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297136409246.33036083297918; Tue, 13 Jan 2026 01:38:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqL-0008Qf-4J; Tue, 13 Jan 2026 04:37:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqJ-0008Ff-2l for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqH-0003Mg-Dn for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:38 -0500 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-577-ZLX95zugNA2pzn8nWkb1mw-1; Tue, 13 Jan 2026 04:37:33 -0500 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 72F79195605B; Tue, 13 Jan 2026 09:37:32 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0EFC930001A2; Tue, 13 Jan 2026 09:37:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297056; 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=R3A2dSjUHqywYaMxMHKJqD/aXpL3mUU9vIKAwjAUR7Y=; b=TLezh32/J4aRsL4e04WNG2rTvZkloVYy3DZOV3AeGrrHmdJgaFpt9Y5+nIjUOJ3TN5BZ8O FNl60IY9F5en95OqxffIVZ26mltpoA/oUPMfLwSND6dXVemtULjDRAdNq55uYiVM3QcAM+ fwRHXdID4zPGBddzLZrFzrZy4GqAYOU= X-MC-Unique: ZLX95zugNA2pzn8nWkb1mw-1 X-Mimecast-MFC-AGG-ID: ZLX95zugNA2pzn8nWkb1mw_1768297052 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Yi Liu , Zhenzhong Duan , Eric Auger , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 17/41] intel_iommu: Replay all pasid bindings when either SRTP or TE bit is changed Date: Tue, 13 Jan 2026 10:36:13 +0100 Message-ID: <20260113093637.1549214-18-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297137704158500 From: Yi Liu When either 'Set Root Table Pointer' or 'Translation Enable' bit is changed, all pasid bindings on host side become stale and need to be updated. Introduce a helper function vtd_replay_pasid_bindings_all() to go through a= ll pasid entries in all passthrough devices to update host side bindings. Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-16-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 2889c29102b1c487f760906e4038274491da1a44..3241af811c4313e22864a0c2fbb= 2d83b89208541 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -76,6 +76,7 @@ struct vtd_iotlb_key { =20 static void vtd_address_space_refresh_all(IntelIOMMUState *s); static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n); +static void vtd_replay_pasid_bindings_all(IntelIOMMUState *s); =20 static void vtd_pasid_cache_reset_locked(IntelIOMMUState *s) { @@ -2629,6 +2630,7 @@ static void vtd_handle_gcmd_srtp(IntelIOMMUState *s) vtd_set_clear_mask_long(s, DMAR_GSTS_REG, 0, VTD_GSTS_RTPS); vtd_reset_caches(s); vtd_address_space_refresh_all(s); + vtd_replay_pasid_bindings_all(s); } =20 /* Set Interrupt Remap Table Pointer */ @@ -2663,6 +2665,7 @@ static void vtd_handle_gcmd_te(IntelIOMMUState *s, bo= ol en) =20 vtd_reset_caches(s); vtd_address_space_refresh_all(s); + vtd_replay_pasid_bindings_all(s); } =20 /* Handle Interrupt Remap Enable/Disable */ @@ -3162,6 +3165,13 @@ static void vtd_pasid_cache_sync(IntelIOMMUState *s,= VTDPASIDCacheInfo *pc_info) vtd_iommu_unlock(s); } =20 +static void vtd_replay_pasid_bindings_all(IntelIOMMUState *s) +{ + VTDPASIDCacheInfo pc_info =3D { .type =3D VTD_INV_DESC_PASIDC_G_GLOBAL= }; + + vtd_pasid_cache_sync(s, &pc_info); +} + static bool vtd_process_pasid_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297087; cv=none; d=zohomail.com; s=zohoarc; b=M7aNZDEX0dfBxYgO4vxC5j5+eOIt6goxg18V4HyqChkZWqaSFDiCOvH+XaEe/FD6xT/M5QCxJ/5O4sZ0kjbN9ltN6pM4jNfI6Cs/7INYrc/I2dwJMTyi6Lm2UqseTTT7leqX3qh7ZpWk/qNg8JyuaiznlEiteFXBa1IWMxIR3wk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297087; 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=ijvRIbxbJxqy9YnkNJldAGrcnYh/shSF6YKQCTZZNhY=; b=GTmHYIymPJA2XQO6wG+9Sbp3ht+6/ybGNojBww6nJ3ggaBz0bsE4aSvqMufZ1hUxXxzWdapJYpjth9VSk2v4uO7VixilxTwut53uN4e2Eq8w49JqzFvIJqOr5bR3XWR4VgD6hhfZ6h/+Tic/w3yRelcDsxlqTA++LRnp5uoaqow= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297087800195.8150475369473; Tue, 13 Jan 2026 01:38:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqS-0000QV-GD; Tue, 13 Jan 2026 04:37:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqM-00006Q-9q for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqK-0003NE-IZ for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:42 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-192-YKW7wA9-MLmBqvbVp8zSYQ-1; Tue, 13 Jan 2026 04:37:36 -0500 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7B6FA18005A7; Tue, 13 Jan 2026 09:37:35 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E2DC630001A2; Tue, 13 Jan 2026 09:37:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297060; 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=ijvRIbxbJxqy9YnkNJldAGrcnYh/shSF6YKQCTZZNhY=; b=C0//3nfiWOuz7jmMC+x5hWFBjg1t0oXnYPegoc/OtPa+PQFNaDELWm31QN0smFGYUSkS0E A5kCrrFg2L08rL82komQ2doPqvaJLPZJEfw+g+xEixcnvuNkkHLd/e22RGczsV3acOMqwr NJRBa7lqWqx5M6Yh0my/RKazqF2cpK0= X-MC-Unique: YKW7wA9-MLmBqvbVp8zSYQ-1 X-Mimecast-MFC-AGG-ID: YKW7wA9-MLmBqvbVp8zSYQ_1768297055 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Yi Liu , Zhenzhong Duan , Eric Auger , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 18/41] intel_iommu: Replay pasid bindings after context cache invalidation Date: Tue, 13 Jan 2026 10:36:14 +0100 Message-ID: <20260113093637.1549214-19-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297089596158500 From: Yi Liu This replays guest pasid bindings after context cache invalidation. Actually, programmer should issue pasid cache invalidation with proper granularity after issuing context cache invalidation. We see old linux such as 6.7.0-rc2 not following the spec, it sends pasid cache invalidation before context cache invalidation, then QEMU depends on context cache invalidation to get pasid entry and setup binding. Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-17-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu.c | 42 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/trace-events | 1 + 2 files changed, 43 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 3241af811c4313e22864a0c2fbb2d83b89208541..08236b85ee67bdb41fb6a9ccbd6= 0ac164e825064 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -77,6 +77,8 @@ struct vtd_iotlb_key { static void vtd_address_space_refresh_all(IntelIOMMUState *s); static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n); static void vtd_replay_pasid_bindings_all(IntelIOMMUState *s); +static void vtd_pasid_cache_sync_locked(gpointer key, gpointer value, + gpointer user_data); =20 static void vtd_pasid_cache_reset_locked(IntelIOMMUState *s) { @@ -2322,6 +2324,37 @@ static void vtd_context_global_invalidate(IntelIOMMU= State *s) * VT-d emulation codes. */ vtd_iommu_replay_all(s); + /* + * Same for pasid cache invalidation, per VT-d spec 6.5.2.1, a global + * context cache invalidation should be followed by global PASID cache + * invalidation. In order to work with guest not following spec, + * handle global PASID cache invalidation here. + */ + vtd_replay_pasid_bindings_all(s); +} + +static void vtd_pasid_cache_devsi(VTDAddressSpace *vtd_as) +{ + IntelIOMMUState *s =3D vtd_as->iommu_state; + PCIBus *bus =3D vtd_as->bus; + uint8_t devfn =3D vtd_as->devfn; + struct vtd_as_key key =3D { + .bus =3D bus, + .devfn =3D devfn, + .pasid =3D vtd_as->pasid, + }; + VTDPASIDCacheInfo pc_info; + + if (!s->fsts || !s->root_scalable || !s->dmar_enabled) { + return; + } + + trace_vtd_pasid_cache_devsi(pci_bus_num(bus), + VTD_PCI_SLOT(devfn), VTD_PCI_FUNC(devfn)); + + /* We fake to be global invalidation just to bypass all checks */ + pc_info.type =3D VTD_INV_DESC_PASIDC_G_GLOBAL; + vtd_pasid_cache_sync_locked(&key, vtd_as, &pc_info); } =20 /* Do a context-cache device-selective invalidation. @@ -2382,6 +2415,15 @@ static void vtd_context_device_invalidate(IntelIOMMU= State *s, * happened. */ vtd_address_space_sync(vtd_as); + /* + * Per spec 6.5.2.1, context flush should be followed by PASID + * cache and iotlb flush. In order to work with a guest which = does + * not follow spec and missed PASID cache flush, e.g., linux + * 6.7.0-rc2, we have vtd_pasid_cache_devsi() to invalidate PA= SID + * cache of passthrough device. Host iommu driver would flush + * piotlb when a pasid unbind is passed down to it. + */ + vtd_pasid_cache_devsi(vtd_as); } } } diff --git a/hw/i386/trace-events b/hw/i386/trace-events index 5a3ee1cf6418ba0713a716266e662ced2e3027f0..5fa5e93b68dcdeed823f99f07fb= 5d55810d3e3a5 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -28,6 +28,7 @@ vtd_pasid_cache_reset(void) "" vtd_inv_desc_pasid_cache_gsi(void) "" vtd_inv_desc_pasid_cache_dsi(uint16_t domain) "Domain selective PC invalid= ation domain 0x%"PRIx16 vtd_inv_desc_pasid_cache_psi(uint16_t domain, uint32_t pasid) "PASID selec= tive PC invalidation domain 0x%"PRIx16" pasid 0x%"PRIx32 +vtd_pasid_cache_devsi(uint8_t bus, uint8_t dev, uint8_t fn) "Dev selective= PC invalidation dev: %02"PRIx8":%02"PRIx8".%02"PRIx8 vtd_re_not_present(uint8_t bus) "Root entry bus %"PRIu8" not present" vtd_ce_not_present(uint8_t bus, uint8_t devfn) "Context entry bus %"PRIu8"= devfn %"PRIu8" not present" vtd_iotlb_page_hit(uint16_t sid, uint64_t addr, uint64_t slpte, uint16_t d= omain) "IOTLB page hit sid 0x%"PRIx16" iova 0x%"PRIx64" slpte 0x%"PRIx64" d= omain 0x%"PRIx16 --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297346; cv=none; d=zohomail.com; s=zohoarc; b=FIOTumrValJD+Cr4n6oBsb7mR+c8+uyad251ne/xN0PTfA2ReoiMB7IePUdPtb3OFTYRFeC+OJ1/ytwEzRWKsSU79f8bOR3YrjwZoLM85nZl1YHGSCIQ113FM6OM1iamk6WjlDyNVKDdApScH8WFPjQ4naMoLaiKGsC9/G9KtRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297346; 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=rAlyKGIhqC0pjf+ESkuNeVeTPdhDbtR7DOGtKHt+UzU=; b=L3PU+uvh6Uicfz53ywDpOoYzZApLFMR6csrRS6ig1aa8uCUxLwRDFVr2vXxNZva/ERxCHYCVTokNmlWpWGd7gQ+cD2lmMyBCqtBkfa7gmSBbkahrN/LvPikdQ3kS1ljkRvMgz/xjxBIk1sTzR7hoJaCSA8xcCe8hEOeqvMmvpzA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297346555425.849056642635; Tue, 13 Jan 2026 01:42:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqX-0000y3-Ng; Tue, 13 Jan 2026 04:37:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqR-0000M6-ML for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqN-0003Nh-0K for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:47 -0500 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-631-iLWs11NkPTijqfq0CieGHg-1; Tue, 13 Jan 2026 04:37:39 -0500 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 2B1281956061; Tue, 13 Jan 2026 09:37:38 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC31A30001A2; Tue, 13 Jan 2026 09:37:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297062; 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=rAlyKGIhqC0pjf+ESkuNeVeTPdhDbtR7DOGtKHt+UzU=; b=gf74qn7+YOdVC85e3/3qIGnRW2KXifKCL2tcjETXOl2vZNNQlcCCN+rPOnyhkLweOPZeF6 8gP/II9e9FjoZYZ4iOKCRprj4BAJ8DaRTDkG+kLnNYYon8Wcdp28gJ3bgbsA/TMyKu9Wxb u2TUQHLll+ffhLNRNb2E7pMcRsJyWTs= X-MC-Unique: iLWs11NkPTijqfq0CieGHg-1 X-Mimecast-MFC-AGG-ID: iLWs11NkPTijqfq0CieGHg_1768297058 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Eric Auger , Yi Liu , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 19/41] intel_iommu: Add migration support with x-flts=on Date: Tue, 13 Jan 2026 10:36:15 +0100 Message-ID: <20260113093637.1549214-20-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297348640158500 From: Zhenzhong Duan When x-flts=3Don, we set up bindings to nested HWPT in host, after migration, VFIO device binds to nesting parent HWPT by default. We need to re-establish the bindings to nested HWPT, or else device DMA will break. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-18-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 08236b85ee67bdb41fb6a9ccbd60ac164e825064..f971cdd14c78fd80df26c0f67d4= abc8cfb35645d 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4090,6 +4090,13 @@ static int vtd_post_load(void *opaque, int version_i= d) */ vtd_switch_address_space_all(iommu); =20 + /* + * Bindings to nested HWPT in host is set up dynamically depending + * on pasid entry configuration from guest. After migration, we + * need to re-establish the bindings before restoring device's DMA. + */ + vtd_replay_pasid_bindings_all(iommu); + return 0; } =20 --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297082; cv=none; d=zohomail.com; s=zohoarc; b=XTqbZmN8C/P8njA3NodH7Udr0qaOIp57VUzPrHUYAlrf1TlCoxJMbylXyJDHxMneTPcUcvmAFYw+Xx3YsjTFUfP2Mdig/0hOUoPdcAfqyHx/xUQ2iGrj6S1Jz1rrR85r+nWLP2cfxOdH3Ed4iuK6s8jDMDGzoIDFLQn1O7Gaf1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297082; 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=iM0nGuuKINqeUk6wxzR01OohYvFbi2TmzKipN46yGhc=; b=b8HcMgCWYX2SdQ3GFuCbefeREtYo88qK+qtHL5AZPkY3SGk+u2pY2QpBNzrpTBaKs3FBsc0e5IO1fzM78L4aspuKnm1aOziD0DPtg4BZGOl9M4upjHMmPlenuBtFEwt8Y+OaqZy+SzEt1KE5IduEpq5ZtiT2gtrIoQuWOuy8XVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297082132976.681288461573; Tue, 13 Jan 2026 01:38:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqV-0000kf-N9; Tue, 13 Jan 2026 04:37:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqS-0000TP-MN for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqQ-0003O1-4H for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:48 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-82-vHKEqijEPBqV3DFSi56s2g-1; Tue, 13 Jan 2026 04:37:42 -0500 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 151D91800624; Tue, 13 Jan 2026 09:37:41 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C1BF30001A2; Tue, 13 Jan 2026 09:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297065; 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=iM0nGuuKINqeUk6wxzR01OohYvFbi2TmzKipN46yGhc=; b=HBXJ74/9+ek/Y7Czh5AziHGdflXQZIiytMH6G/lSX5BHv9pxOpGwmxlEmq+xuGART6iUt6 3RDOLqrTh4uAKxS4gqGoA/v9DgxzoHkS8LkJRIJyJ+7F4YoL4MB3Z/VRs7kC+kSoqomta1 Iy3Qc6ZLZtdGkJPhpRlqjeZ4XExt/PM= X-MC-Unique: vHKEqijEPBqV3DFSi56s2g-1 X-Mimecast-MFC-AGG-ID: vHKEqijEPBqV3DFSi56s2g_1768297061 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Eric Auger , Yi Liu , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 20/41] intel_iommu: Enable host device when x-flts=on in scalable mode Date: Tue, 13 Jan 2026 10:36:16 +0100 Message-ID: <20260113093637.1549214-21-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297083479158500 From: Zhenzhong Duan Now that all infrastructures of supporting passthrough device running with first stage translation are there, enable it now. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-19-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_accel.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 1f068005d8fa8b2161247e1e2386db5a60dbbdc5..250232b5a979e9b34d161fde554= fd0c64b0cd3d9 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -47,9 +47,7 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMM= UDevice *vtd_hiod, return false; } =20 - error_setg(errp, - "host IOMMU is incompatible with guest first stage translat= ion"); - return false; + return true; } =20 VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as) --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297278; cv=none; d=zohomail.com; s=zohoarc; b=bnJnp3dLiKZbcAUoouc+TNMqO/LySfnvHwQSySDn7vU7TIF124gsVH2tKfNfYwkCQXyprLr2jhjQpDfJZwj1ntWVtFXkBtUq6fl8rawz1Z9Yzq/798AXQXYb8B5Huj689BfD0MhGt8Y1kHDlMBuW209/b3lMd7WaKrV8kyTLcsA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297278; 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=3HiLCAxba8GXuTt0rFTrtkhRlm4inQkwIRGs/a9Fcnw=; b=B7RIb0lUADoxMiyN2E+LtZ55jHV2vCLQaiHYXj+Tk3MIjs9w8ech+M+neB4hbUkZ3/UTt7b1mzpyvmiq1NPWJJbotIYBjhydHTBxZshl/W47klcA/x00O2W6o+97LJ1GwOygnrHQ1+JIa7ZhZRPZ5GihHJUnvUjA7Frbjohbhj4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297278924491.2221301241391; Tue, 13 Jan 2026 01:41:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqW-0000qK-EZ; Tue, 13 Jan 2026 04:37:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqT-0000YL-In for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqR-0003Oa-W3 for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:49 -0500 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-38-Ls5P-rLDNYK2M4rTi5FM4A-1; Tue, 13 Jan 2026 04:37:45 -0500 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 8659C1956094; Tue, 13 Jan 2026 09:37:44 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8761630001A2; Tue, 13 Jan 2026 09:37:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297067; 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=3HiLCAxba8GXuTt0rFTrtkhRlm4inQkwIRGs/a9Fcnw=; b=Qi+iki/ZVgl8pOeSf49siQEUeao9kRgGIHngR2m2iwQkvQXYQTW3tvlVVoY+j0xBSZYTD0 b197R6McgVIRgR+bIwV+JGM/fdVyCUOX/zLwA/Ozo8HQUa1drqqXWNvKF1KB08lm0ZPrfV 0N1hkWSHVhYviU5tLOgejH8ntBm4G1w= X-MC-Unique: Ls5P-rLDNYK2M4rTi5FM4A-1 X-Mimecast-MFC-AGG-ID: Ls5P-rLDNYK2M4rTi5FM4A_1768297064 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , Eric Auger , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 21/41] docs/devel: Add IOMMUFD nesting documentation Date: Tue, 13 Jan 2026 10:36:17 +0100 Message-ID: <20260113093637.1549214-22-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297280510158500 From: Zhenzhong Duan Add documentation about using IOMMUFD backed VFIO device with intel_iommu w= ith x-flts=3Don. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Yi Liu Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260106061304.314546-20-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- docs/devel/vfio-iommufd.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/devel/vfio-iommufd.rst b/docs/devel/vfio-iommufd.rst index b37098e1b625d9be0368e53b7492db64828c88c3..2d6e60dce1d38f1de136c3d65f3= c396aef9e0805 100644 --- a/docs/devel/vfio-iommufd.rst +++ b/docs/devel/vfio-iommufd.rst @@ -152,3 +152,20 @@ RAM discarding for mdev. =20 ``vfio-ap`` and ``vfio-ccw`` devices don't have same issue as their backend devices are always mdev and RAM discarding is force enabled. + +Usage with intel_iommu featuring x-flts=3Don +------------------------------------------ + +Only IOMMUFD backed VFIO device is supported when intel_iommu is configured +with x-flts=3Don, for legacy container backed VFIO device, below error sho= ws: + +.. code-block:: none + + qemu-system-x86_64: -device vfio-pci,host=3D0000:02:00.0: vfio 0000:02= :00.0: Failed to set vIOMMU: Need IOMMUFD backend when x-flts=3Don + +VFIO device under PCI bridge is unsupported, use PCIE bridge if necessary, +otherwise below error shows: + +.. code-block:: none + + qemu-system-x86_64: -device vfio-pci,host=3D0000:02:00.0,bus=3Dbridge1= ,iommufd=3Diommufd0: vfio 0000:02:00.0: Failed to set vIOMMU: Host device d= ownstream to a PCI bridge is unsupported when x-flts=3Don --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297101; cv=none; d=zohomail.com; s=zohoarc; b=Qxagn0x8mbIQbSC/e4CCOsq2MbtkK2IohDimDYv6vyezTsj2nSYfVxBVgufErPrGaB7eMBZPpOPpwE6277/MNcd+A8m5uyl49AgJvDFSU+zLLwdJu9xnN47SZ66WK+ruNeXGPJc9lnFFtzqrjwR1E/EryzK3pYGn2xjgeAlVn2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297101; 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=o5tqwJ/c3cR/g2ZIcrgCqfs0Sk0VmFjx1wb4iWXHXaA=; b=ShqA3fOKIsJjf+PqN84plvBMTar8FHLW9zLo9whxCYSgUQAd6ONpE/Hu3Lw86HMpvaSKgwqI5KSTMmZcmlPzlaki/pAyuXWVwbtbURdzPCPIVTJael6EqIcM/jaDc6RAIocgLREcniIndZkdL8hTGmpqomJBE1Mz3Uj1uMAQtY0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176829710121365.84963710389127; Tue, 13 Jan 2026 01:38:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqa-0001Lk-HU; Tue, 13 Jan 2026 04:37:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqY-000161-Iz for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqW-0003PV-UI for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:54 -0500 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-42-bliF4gsBMcS-hU4VNxnbtw-1; Tue, 13 Jan 2026 04:37:48 -0500 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 88548195605B; Tue, 13 Jan 2026 09:37:47 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 046FE30001A2; Tue, 13 Jan 2026 09:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297072; 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=o5tqwJ/c3cR/g2ZIcrgCqfs0Sk0VmFjx1wb4iWXHXaA=; b=B18ARniiQhB/n7dvcli0pPXRMg4zr18vB9wZosZohaP7TQQyHRV0gzQzqMv4AaAQ75u5eA YgzIrZJaxWfmd7w5EVAe+uEgPA5V7AzhkjsbluZwc89a9LtRxVSqwsWw9Lkw1U29MjbfBn BKDjW7eC9iezEBD05CWBJ0NYghhVz70= X-MC-Unique: bliF4gsBMcS-hU4VNxnbtw-1 X-Mimecast-MFC-AGG-ID: bliF4gsBMcS-hU4VNxnbtw_1768297067 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?= , Yi Liu , Xudong Hao , Giovannio Cabiddu , Rohith S R Subject: [PULL 22/41] vfio/iommufd: Add framework code to support getting dirty bitmap before unmap Date: Tue, 13 Jan 2026 10:36:18 +0100 Message-ID: <20260113093637.1549214-23-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297101567158500 From: Zhenzhong Duan Currently we support device and iommu dirty tracking, device dirty tracking is preferred. Add the framework code in iommufd_cdev_unmap() to choose either device or iommu dirty tracking, just like vfio_legacy_dma_unmap_one(). Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Yi Liu Tested-by: Xudong Hao Tested-by: Giovannio Cabiddu Tested-by: Rohith S R Link: https://lore.kernel.org/qemu-devel/20251218062643.624796-2-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index e5328c63a366076199015b25f55d273b91a4327a..f56349faf5669cfeed10d7fc5e8= d3bf8397bb04d 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -61,14 +61,42 @@ static int iommufd_cdev_unmap(const VFIOContainer *bcon= tainer, IOMMUTLBEntry *iotlb, bool unmap_all) { const VFIOIOMMUFDContainer *container =3D VFIO_IOMMU_IOMMUFD(bcontaine= r); + IOMMUFDBackend *be =3D container->be; + uint32_t ioas_id =3D container->ioas_id; + bool need_dirty_sync =3D false; + Error *local_err =3D NULL; + int ret; =20 if (unmap_all) { size =3D UINT64_MAX; } =20 - /* TODO: Handle dma_unmap_bitmap with iotlb args (migration) */ - return iommufd_backend_unmap_dma(container->be, - container->ioas_id, iova, size); + if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) { + if (!vfio_container_devices_dirty_tracking_is_supported(bcontainer= ) && + bcontainer->dirty_pages_supported) { + /* TODO: query dirty bitmap before DMA unmap */ + return iommufd_backend_unmap_dma(be, ioas_id, iova, size); + } + + need_dirty_sync =3D true; + } + + ret =3D iommufd_backend_unmap_dma(be, ioas_id, iova, size); + if (ret) { + return ret; + } + + if (need_dirty_sync) { + ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, size, + iotlb->translated_addr, + &local_err); + if (ret) { + error_report_err(local_err); + return ret; + } + } + + return 0; } =20 static bool iommufd_cdev_kvm_device_add(VFIODevice *vbasedev, Error **errp) --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297167; cv=none; d=zohomail.com; s=zohoarc; b=GuwT+Vy9cgMCx+f717cNtklBPUFj/NJSg6QFB3deLER//utQkUl724j3s7HDt3mVMYAQ3axmf4k9s4l4G70t3M19rY8W6UfE9lAEt/mSzxuAx545GuWA4AzZmOCG8r5XPGHsZ0rs+veQluvbyvVXWOkOkf/KCp5M6nKXpMY45LI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297167; 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=gjuUPb1vbhlPDXI27DbfmDSRpGuiGT5u895EaUv2uyw=; b=eGURk4ss/jrqWVZnlKZ5Re3qbne7aRsZJHAgAxHlbu392Gx80IlffGNCSde+LDNTUsS7Y42RKPJfth07vMnJxUAmbOr22LHtidYy7mzJaYAPKgefWMo/Ta7De41I2unqk2CsWu0n4AEFe2+2IwO6XrGVbNCDCmeXLPGK9JTR7oM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297167540627.5893492633245; Tue, 13 Jan 2026 01:39:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqg-00026W-Ps; Tue, 13 Jan 2026 04:38:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqe-0001nW-4Y for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqc-0003QM-Dk for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:59 -0500 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-364-t1DVyuPrPuSaXeqAnHymbw-1; Tue, 13 Jan 2026 04:37:52 -0500 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 CE4F51956080; Tue, 13 Jan 2026 09:37:50 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E377330001A2; Tue, 13 Jan 2026 09:37:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297077; 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=gjuUPb1vbhlPDXI27DbfmDSRpGuiGT5u895EaUv2uyw=; b=UK1kwEIdUb6o7yEZ/aUl0qXLaqHO8RwIQCjrRgSFVvDNhfHRivGOGiLjOad0lXCbTbPGgz L6HxvBXQotoD6UCXGi9iZ5B99026C42xuVm+yneo8pylyCOnKIF7ENVBOxgERYZEftEvEO Tc4J/uSHcKdb4stqw7XX03wMhJRmOIU= X-MC-Unique: t1DVyuPrPuSaXeqAnHymbw-1 X-Mimecast-MFC-AGG-ID: t1DVyuPrPuSaXeqAnHymbw_1768297070 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Joao Martins , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Yi Liu , Xudong Hao , Giovannio Cabiddu , Rohith S R Subject: [PULL 23/41] vfio/iommufd: Query dirty bitmap before DMA unmap Date: Tue, 13 Jan 2026 10:36:19 +0100 Message-ID: <20260113093637.1549214-24-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297167820158500 From: Zhenzhong Duan When an existing mapping is unmapped, there could already be dirty bits which need to be recorded before unmap. If query dirty bitmap fails, we still need to do unmapping or else there is stale mapping and it's risky to guest. Co-developed-by: Joao Martins Signed-off-by: Joao Martins Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Yi Liu Tested-by: Xudong Hao Tested-by: Giovannio Cabiddu Tested-by: Rohith S R Link: https://lore.kernel.org/qemu-devel/20251218062643.624796-3-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index f56349faf5669cfeed10d7fc5e8d3bf8397bb04d..6d6244d7b9723def647f3dd4eec= 7ef1558415bb2 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -65,7 +65,7 @@ static int iommufd_cdev_unmap(const VFIOContainer *bconta= iner, uint32_t ioas_id =3D container->ioas_id; bool need_dirty_sync =3D false; Error *local_err =3D NULL; - int ret; + int ret, unmap_ret; =20 if (unmap_all) { size =3D UINT64_MAX; @@ -74,8 +74,21 @@ static int iommufd_cdev_unmap(const VFIOContainer *bcont= ainer, if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) { if (!vfio_container_devices_dirty_tracking_is_supported(bcontainer= ) && bcontainer->dirty_pages_supported) { - /* TODO: query dirty bitmap before DMA unmap */ - return iommufd_backend_unmap_dma(be, ioas_id, iova, size); + ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, si= ze, + iotlb->translated_addr, + &local_err); + if (ret) { + error_report_err(local_err); + } + /* Unmap stale mapping even if query dirty bitmap fails */ + unmap_ret =3D iommufd_backend_unmap_dma(be, ioas_id, iova, siz= e); + + /* + * If dirty tracking fails, return the failure to VFIO core to + * fail the migration, or else there will be dirty pages missed + * to be migrated. + */ + return unmap_ret ? : ret; } =20 need_dirty_sync =3D true; --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297178; cv=none; d=zohomail.com; s=zohoarc; b=Kjcds9MuQWS6QAAfkcFwYUdwsEjAaLIqmYYph2DXGXyDKx1kFwKsrdrFJ6eB9PBgGJuNDTOLNai3J4NKc+voMgJrmnobgQ83sn6g8sOLXWmZIHJ7bbtEO1N3F09yyCj5yE0NZXEZparg8eyQnXdd0Ozn/vttOH0QUoU2UNx3GyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297178; 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=abQudyZ2QRsAkzckmelFBM2Bf5q4iemoZhqXlk/M6X8=; b=btpWQmLt4easLY/fa+hPV3oekSTi5Tj3GFDa51hxfOeL7GgFyKdQ6JPJQu+d+sJN5QBgI34ORMiscpO6oz0Bp3HtyOpR0nJFkxYChPU/F5mGhk8vAIYruVd7GWEiZH2FDDmVBSf4Cj3DJv3Gmu5Y2vdCJcT/U9vU/flPgy5ExpU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297178268152.64640779564854; Tue, 13 Jan 2026 01:39:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqg-00025J-J8; Tue, 13 Jan 2026 04:38:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqe-0001nD-2p for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqc-0003QE-7r for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:37:59 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-264-qDzZAHdnNpqZHwsbgs7iYg-1; Tue, 13 Jan 2026 04:37:54 -0500 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 063D618002C4; Tue, 13 Jan 2026 09:37:53 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4AA4B30001A2; Tue, 13 Jan 2026 09:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297077; 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=abQudyZ2QRsAkzckmelFBM2Bf5q4iemoZhqXlk/M6X8=; b=QUh6SO4XAPHuEbpYckM6/iRiNyxsO4Cdgtw/qVJiTybQ0HkpILdX9Vmw51GF5e57EpC2Eh h7vajcYr/0+MgZmQqkxMKYpcU+Nd83CMUXeQzl5uER9L/1ygH8FvW1rqIL+lylb9GvwGiV 8tFpTv/B7+UHMHG6JPOFC14u+oYhlyo= X-MC-Unique: qDzZAHdnNpqZHwsbgs7iYg-1 X-Mimecast-MFC-AGG-ID: qDzZAHdnNpqZHwsbgs7iYg_1768297073 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?= , Yi Liu Subject: [PULL 24/41] vfio/container-legacy: rename vfio_dma_unmap_bitmap() to vfio_legacy_dma_unmap_get_dirty_bitmap() Date: Tue, 13 Jan 2026 10:36:20 +0100 Message-ID: <20260113093637.1549214-25-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297179917158500 From: Zhenzhong Duan This is to follow naming style in container-legacy.c to have low level func= tions with vfio_legacy_ prefix. No functional changes. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Yi Liu Link: https://lore.kernel.org/qemu-devel/20251218062643.624796-4-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/container-legacy.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/vfio/container-legacy.c b/hw/vfio/container-legacy.c index 32c260b345194532c5a1c155a61aafa345d3ecae..48bcbc0264effc100642ff59f51= 0533bf0ad2180 100644 --- a/hw/vfio/container-legacy.c +++ b/hw/vfio/container-legacy.c @@ -68,9 +68,10 @@ static int vfio_ram_block_discard_disable(VFIOLegacyCont= ainer *container, } } =20 -static int vfio_dma_unmap_bitmap(const VFIOLegacyContainer *container, - hwaddr iova, uint64_t size, - IOMMUTLBEntry *iotlb) +static int +vfio_legacy_dma_unmap_get_dirty_bitmap(const VFIOLegacyContainer *containe= r, + hwaddr iova, uint64_t size, + IOMMUTLBEntry *iotlb) { const VFIOContainer *bcontainer =3D VFIO_IOMMU(container); struct vfio_iommu_type1_dma_unmap *unmap; @@ -141,7 +142,8 @@ static int vfio_legacy_dma_unmap_one(const VFIOLegacyCo= ntainer *container, if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) { if (!vfio_container_devices_dirty_tracking_is_supported(bcontainer= ) && bcontainer->dirty_pages_supported) { - return vfio_dma_unmap_bitmap(container, iova, size, iotlb); + return vfio_legacy_dma_unmap_get_dirty_bitmap(container, iova,= size, + iotlb); } =20 need_dirty_sync =3D true; --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297109; cv=none; d=zohomail.com; s=zohoarc; b=dhvWB8l64Dh/5tW+vkTDdUVUl7dBqdAAUOmgznnT0dr0XnnL6x1YvPbCdAybehjJDgigrsJ30gMx5tTJdJnBJfxHXY4Xr8Zue+AhcJWZNWpOBKeKP745C/NTCiksRFCTqYkhFdRHnzajILxS275AknHv5y4SUrnp0Z0i+A8ahv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297109; 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=Zt4qz9zkLm4guZEvlZSD9b2rLiteAgTtol3j0jSCt7k=; b=YOVbo0YB4f8wPt0sJeAKTU4tzPwD1J2/vzREO8CusEWpd/lfrs3vy0/D9mCjw6/vBBFl10ioNHxOYUybCE5xVTmZ6x1bDfZuY+7KkPdkD6a0ZzSHZ2NkSR6Njaj+VLYLkh9cVVKLuWEjJg/4Jl7lRIUqlzs/dY2fFxyPjk6McNc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297109293478.88714071829736; Tue, 13 Jan 2026 01:38:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqm-0002lO-Tf; Tue, 13 Jan 2026 04:38:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqj-0002W1-Tj for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqh-0003RL-OZ for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:05 -0500 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-611-vTF202MlOPSf76pRdC3_Ng-1; Tue, 13 Jan 2026 04:37:57 -0500 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 1F7EF1954B24; Tue, 13 Jan 2026 09:37:56 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 771BA30001A2; Tue, 13 Jan 2026 09:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297083; 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=Zt4qz9zkLm4guZEvlZSD9b2rLiteAgTtol3j0jSCt7k=; b=GlgcNszWCtlZZpnzVk7aYiDSId/yExVRu0J+a3LN52MiAY8+rwZQRIl20G0FBI7Qwn9A9g cukGzX6D/7KM5z18XN3ch5TpceYXrdRWt8ioJGHIoY6fUUhTA3UI1em4XUG/u8EGwTReN8 ZL5593jI66YlDUumuNSuJ3xoCnGodXc= X-MC-Unique: vTF202MlOPSf76pRdC3_Ng-1 X-Mimecast-MFC-AGG-ID: vTF202MlOPSf76pRdC3_Ng_1768297076 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Joao Martins , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Yi Liu , Giovannio Cabiddu , Rohith S R Subject: [PULL 25/41] vfio: Add a backend_flag parameter to vfio_container_query_dirty_bitmap() Date: Tue, 13 Jan 2026 10:36:21 +0100 Message-ID: <20260113093637.1549214-26-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297109894158500 From: Joao Martins This new parameter will be used in following patch, currently 0 is passed. Signed-off-by: Joao Martins Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Yi Liu Tested-by: Giovannio Cabiddu Tested-by: Rohith S R Link: https://lore.kernel.org/qemu-devel/20251218062643.624796-5-zhenzhong.= duan@intel.com [ clg: Fixed subject typo ] Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container.h | 8 ++++++-- hw/vfio-user/container.c | 5 +++-- hw/vfio/container-legacy.c | 5 +++-- hw/vfio/container.c | 15 +++++++++------ hw/vfio/iommufd.c | 7 ++++--- hw/vfio/listener.c | 6 +++--- hw/vfio/trace-events | 2 +- 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-contai= ner.h index c4b58d664b7e705d29be0e7116d609c6df0d42a9..9f6e8cedfc9541e84558d74bdb1= 56e4963a68639 100644 --- a/include/hw/vfio/vfio-container.h +++ b/include/hw/vfio/vfio-container.h @@ -99,7 +99,9 @@ bool vfio_container_devices_dirty_tracking_is_supported( const VFIOContainer *bcontainer); int vfio_container_query_dirty_bitmap(const VFIOContainer *bcontainer, uint64_t iova, uint64_t size, - hwaddr translated_addr, Error **errp= ); + uint64_t backend_flag, + hwaddr translated_addr, + Error **errp); =20 GList *vfio_container_get_iova_ranges(const VFIOContainer *bcontainer); =20 @@ -253,12 +255,14 @@ struct VFIOIOMMUClass { * @vbmap: #VFIOBitmap internal bitmap structure * @iova: iova base address * @size: size of iova range + * @backend_flag: flags for backend, opaque to upper layer container * @errp: pointer to Error*, to store an error if it happens. * * Returns zero to indicate success and negative for error. */ int (*query_dirty_bitmap)(const VFIOContainer *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp); + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, + uint64_t backend_flag, Error **errp); /* PCI specific */ int (*pci_hot_reset)(VFIODevice *vbasedev, bool single); =20 diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c index d5275a463b8d99eae967114e4e0ade70b2076570..796289a469033ef47fa7199dbe3= 0d02f0ba83ada 100644 --- a/hw/vfio-user/container.c +++ b/hw/vfio-user/container.c @@ -163,8 +163,9 @@ vfio_user_set_dirty_page_tracking(const VFIOContainer *= bcontainer, } =20 static int vfio_user_query_dirty_bitmap(const VFIOContainer *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, - hwaddr size, Error **errp) + VFIOBitmap *vbmap, hwaddr iova, + hwaddr size, uint64_t backend_flag, + Error **errp) { error_setg_errno(errp, ENOTSUP, "Not supported"); return -ENOTSUP; diff --git a/hw/vfio/container-legacy.c b/hw/vfio/container-legacy.c index 48bcbc0264effc100642ff59f510533bf0ad2180..625f151364c060135076cd19537= 810bbe61ab998 100644 --- a/hw/vfio/container-legacy.c +++ b/hw/vfio/container-legacy.c @@ -154,7 +154,7 @@ static int vfio_legacy_dma_unmap_one(const VFIOLegacyCo= ntainer *container, } =20 if (need_dirty_sync) { - ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, size, + ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, size, = 0, iotlb->translated_addr, &local_err); if (ret) { error_report_err(local_err); @@ -255,7 +255,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainer= *bcontainer, } =20 static int vfio_legacy_query_dirty_bitmap(const VFIOContainer *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error *= *errp) + VFIOBitmap *vbmap, hwaddr iova, hwaddr = size, + uint64_t backend_flag, Error **errp) { const VFIOLegacyContainer *container =3D VFIO_IOMMU_LEGACY(bcontainer); struct vfio_iommu_type1_dirty_bitmap *dbitmap; diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 5993d9054579077683720959cfc8e0d76eef519d..9881f5df2cc34262ae6aa88aa93= 7659e7b197cd2 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -213,13 +213,13 @@ static int vfio_device_dma_logging_report(VFIODevice = *vbasedev, hwaddr iova, =20 static int vfio_container_iommu_query_dirty_bitmap( const VFIOContainer *bcontainer, VFIOBitmap *vbmap, hwaddr iova, - hwaddr size, Error **errp) + hwaddr size, uint64_t backend_flag, Error **errp) { VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); =20 g_assert(vioc->query_dirty_bitmap); return vioc->query_dirty_bitmap(bcontainer, vbmap, iova, size, - errp); + backend_flag, errp); } =20 static int vfio_container_devices_query_dirty_bitmap( @@ -247,7 +247,9 @@ static int vfio_container_devices_query_dirty_bitmap( =20 int vfio_container_query_dirty_bitmap(const VFIOContainer *bcontainer, uint64_t iova, uint64_t size, - hwaddr translated_addr, Error **errp) + uint64_t backend_flag, + hwaddr translated_addr, + Error **errp) { bool all_device_dirty_tracking =3D vfio_container_devices_dirty_tracking_is_supported(bcontainer); @@ -274,7 +276,7 @@ int vfio_container_query_dirty_bitmap(const VFIOContain= er *bcontainer, errp); } else { ret =3D vfio_container_iommu_query_dirty_bitmap(bcontainer, &vbmap= , iova, size, - errp); + backend_flag, errp); } =20 if (ret) { @@ -285,8 +287,9 @@ int vfio_container_query_dirty_bitmap(const VFIOContain= er *bcontainer, translated_addr, vbmap.pages); =20 - trace_vfio_container_query_dirty_bitmap(iova, size, vbmap.size, - translated_addr, dirty_pages); + trace_vfio_container_query_dirty_bitmap(iova, size, backend_flag, + vbmap.size, translated_addr, + dirty_pages); out: g_free(vbmap.bitmap); =20 diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 6d6244d7b9723def647f3dd4eec7ef1558415bb2..a3fb674f50eea549d0aaaaa7138= e8981d343697d 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -74,7 +74,7 @@ static int iommufd_cdev_unmap(const VFIOContainer *bconta= iner, if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) { if (!vfio_container_devices_dirty_tracking_is_supported(bcontainer= ) && bcontainer->dirty_pages_supported) { - ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, si= ze, + ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, si= ze, 0, iotlb->translated_addr, &local_err); if (ret) { @@ -100,7 +100,7 @@ static int iommufd_cdev_unmap(const VFIOContainer *bcon= tainer, } =20 if (need_dirty_sync) { - ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, size, + ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, size, = 0, iotlb->translated_addr, &local_err); if (ret) { @@ -216,7 +216,8 @@ err: =20 static int iommufd_query_dirty_bitmap(const VFIOContainer *bcontainer, VFIOBitmap *vbmap, hwaddr iova, - hwaddr size, Error **errp) + hwaddr size, uint64_t backend_flag, + Error **errp) { VFIOIOMMUFDContainer *container =3D VFIO_IOMMU_IOMMUFD(bcontainer); unsigned long page_size =3D qemu_real_host_page_size(); diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 7af010753597ee99eee12d32f38e945322cbbbbf..62699cb772d786c1510318dff73= 973ef4d297177 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -1083,7 +1083,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) translated_addr =3D memory_region_get_ram_addr(mr) + xlat; =20 ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, iotlb->add= r_mask + 1, - translated_addr, &local_err); + 0, translated_addr, &local_err); if (ret) { error_prepend(&local_err, "vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx", " @@ -1119,7 +1119,7 @@ static int vfio_ram_discard_query_dirty_bitmap(Memory= RegionSection *section, * Sync the whole mapped region (spanning multiple individual mappings) * in one go. */ - ret =3D vfio_container_query_dirty_bitmap(vrdl->bcontainer, iova, size, + ret =3D vfio_container_query_dirty_bitmap(vrdl->bcontainer, iova, size= , 0, translated_addr, &local_err); if (ret) { error_report_err(local_err); @@ -1204,7 +1204,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainer *bcon= tainer, =20 return vfio_container_query_dirty_bitmap(bcontainer, REAL_HOST_PAGE_ALIGN(section->offset_within_address_spa= ce), - int128_get64(section->size), translated_addr, errp); + int128_get64(section->size), 0, translated_addr, errp); } =20 static void vfio_listener_log_sync(MemoryListener *listener, diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 1e895448cd9b4f6b0dd5bb445de4acef6090ec62..3c62bab7647a7d027038444fa4b= 164182d3feb2b 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -105,7 +105,7 @@ vfio_device_dirty_tracking_start(int nr_ranges, uint64_= t min32, uint64_t max32, vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 =20 # container.c -vfio_container_query_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t b= itmap_size, uint64_t translated_addr, uint64_t dirty_pages) "iova=3D0x%"PRI= x64" size=3D 0x%"PRIx64" bitmap_size=3D0x%"PRIx64" gpa=3D0x%"PRIx64" dirty_= pages=3D%"PRIu64 +vfio_container_query_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t b= ackend_flag, uint64_t bitmap_size, uint64_t translated_addr, uint64_t dirty= _pages) "iova=3D0x%"PRIx64" size=3D0x%"PRIx64" backend_flag=3D0x%"PRIx64" b= itmap_size=3D0x%"PRIx64" gpa=3D0x%"PRIx64" dirty_pages=3D%"PRIu64 =20 # container-legacy.c vfio_container_disconnect(int fd) "close container->fd=3D%d" --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297147; cv=none; d=zohomail.com; s=zohoarc; b=bQY+HeFAWC2BxPukgS2GqlfJKnvb5K3E0Dh5+2nev84JKxlZm+1yHBV4U5AL35P9/UHF8bhI9oF9Ff3T3z7ZglCNJIw1pQi5Nif7oAc15TiwrLIQy0eVjvFOBGkP/GEMLfUtzT/EqCeUY9mPSKB8tTF6DtFM5+K01PTydVrV9oI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297147; 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=z8gk1bCnKu8Te7ra5bmjoWf+dUR7+QJGGaFv+IG328A=; b=S/ejQZ5IHzH38YyUAn+QwY8XJ2uAfd0dGSF5Jj9+PX5yGZeivOALsfzWuEPxrnHC5Is9NkLFAN2MaBKky0EyKPmKGkNj0zVBWIX0tT/megtRyot2u4c8Mp/2f54lWFmRxHY/S8nd1DVQhD3x5K32bxahd63hwUX4eA7cS6bQP8A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297147936663.2854134031328; Tue, 13 Jan 2026 01:39:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqo-0002sq-Td; Tue, 13 Jan 2026 04:38:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaql-0002hV-Q0 for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqj-0003Rl-5K for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:07 -0500 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-635-ng4U8bwcO6inJuzuB5pOvA-1; Tue, 13 Jan 2026 04:38:00 -0500 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 3FAAE1955DD1; Tue, 13 Jan 2026 09:37:59 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8F3DD30001A8; Tue, 13 Jan 2026 09:37:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297084; 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=z8gk1bCnKu8Te7ra5bmjoWf+dUR7+QJGGaFv+IG328A=; b=Cafh9F2ifJzlXM9WRuNyKdXTPjg/y8i48rLUt+6+cjPH2edz2ajh1DgkBjXx82n56/8/nz ky/u2MBU/wwUs2pxj0IG5hoq+Q87j71v/UkQk86OVzhKgHCd/hOdQLM1JIT+V+rHWkYoo3 SHmZGwhzntcvqIqcbxu2jmGr5nEuU1k= X-MC-Unique: ng4U8bwcO6inJuzuB5pOvA-1 X-Mimecast-MFC-AGG-ID: ng4U8bwcO6inJuzuB5pOvA_1768297079 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Joao Martins , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Yi Liu , Xudong Hao , Giovannio Cabiddu , Rohith S R Subject: [PULL 26/41] vfio/iommufd: Add IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR flag support Date: Tue, 13 Jan 2026 10:36:22 +0100 Message-ID: <20260113093637.1549214-27-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297149699158500 From: Zhenzhong Duan Pass IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR when doing the last dirty bitmap query right before unmap, no PTEs flushes. This accelerates the query without issue because unmap will tear down the mapping anyway. Co-developed-by: Joao Martins Signed-off-by: Joao Martins Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Yi Liu Tested-by: Xudong Hao Tested-by: Giovannio Cabiddu Tested-by: Rohith S R Link: https://lore.kernel.org/qemu-devel/20251218062643.624796-6-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- include/system/iommufd.h | 2 +- backends/iommufd.c | 5 +++-- hw/vfio/iommufd.c | 5 +++-- backends/trace-events | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/system/iommufd.h b/include/system/iommufd.h index 9f5eb872454a8d09d1b9e8c6d5dd50fa2a832068..1392706b83ae38501f543a7c65e= bc3528e3d295f 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -64,7 +64,7 @@ bool iommufd_backend_set_dirty_tracking(IOMMUFDBackend *b= e, uint32_t hwpt_id, bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id, uint64_t iova, ram_addr_t size, uint64_t page_size, uint64_t *data, - Error **errp); + uint64_t flags, Error **errp); bool iommufd_backend_invalidate_cache(IOMMUFDBackend *be, uint32_t id, uint32_t data_type, uint32_t entry_l= en, uint32_t *entry_num, void *data, diff --git a/backends/iommufd.c b/backends/iommufd.c index fdfb7c9d67197da11d35290ba2f44e0b005c2690..086bd67aeacbf6d2ae56031f7d3= 9e2951956c2b2 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -361,7 +361,7 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *b= e, uint32_t hwpt_id, uint64_t iova, ram_addr_t size, uint64_t page_size, uint64_t *data, - Error **errp) + uint64_t flags, Error **errp) { int ret; struct iommu_hwpt_get_dirty_bitmap get_dirty_bitmap =3D { @@ -371,11 +371,12 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend = *be, .length =3D size, .page_size =3D page_size, .data =3D (uintptr_t)data, + .flags =3D flags, }; =20 ret =3D ioctl(be->fd, IOMMU_HWPT_GET_DIRTY_BITMAP, &get_dirty_bitmap); trace_iommufd_backend_get_dirty_bitmap(be->fd, hwpt_id, iova, size, - page_size, ret ? errno : 0); + flags, page_size, ret ? errno := 0); if (ret) { error_setg_errno(errp, errno, "IOMMU_HWPT_GET_DIRTY_BITMAP (iova: 0x%"HWADDR_PR= Ix diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index a3fb674f50eea549d0aaaaa7138e8981d343697d..0bf68620d2c9a7a5e21553b9cc2= 75e627b73327f 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -74,7 +74,8 @@ static int iommufd_cdev_unmap(const VFIOContainer *bconta= iner, if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) { if (!vfio_container_devices_dirty_tracking_is_supported(bcontainer= ) && bcontainer->dirty_pages_supported) { - ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, si= ze, 0, + ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, si= ze, + IOMMU_HWPT_GET_DIRTY_B= ITMAP_NO_CLEAR, iotlb->translated_addr, &local_err); if (ret) { @@ -231,7 +232,7 @@ static int iommufd_query_dirty_bitmap(const VFIOContain= er *bcontainer, if (!iommufd_backend_get_dirty_bitmap(container->be, hwpt->hwpt_id, iova, size, page_size, (uint64_t *)vbmap->bitmap, - errp)) { + backend_flag, errp)) { return -EINVAL; } } diff --git a/backends/trace-events b/backends/trace-events index 56132d3fd22b5a217b07349c74f17e50d553a799..e1992ba12f0409f020b5456831c= 16919b55e9c32 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -19,5 +19,5 @@ iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " = iommufd=3D%d ioas=3D%d" iommufd_backend_alloc_hwpt(int iommufd, uint32_t dev_id, uint32_t pt_id, u= int32_t flags, uint32_t hwpt_type, uint32_t len, uint64_t data_ptr, uint32_= t out_hwpt_id, int ret) " iommufd=3D%d dev_id=3D%u pt_id=3D%u flags=3D0x%x = hwpt_type=3D%u len=3D%u data_ptr=3D0x%"PRIx64" out_hwpt=3D%u (%d)" iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=3D%d = id=3D%d (%d)" iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int r= et) " iommufd=3D%d hwpt=3D%u enable=3D%d (%d)" -iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t i= ova, uint64_t size, uint64_t page_size, int ret) " iommufd=3D%d hwpt=3D%u i= ova=3D0x%"PRIx64" size=3D0x%"PRIx64" page_size=3D0x%"PRIx64" (%d)" +iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t i= ova, uint64_t size, uint64_t flags, uint64_t page_size, int ret) " iommufd= =3D%d hwpt=3D%u iova=3D0x%"PRIx64" size=3D0x%"PRIx64" flags=3D0x%"PRIx64" p= age_size=3D0x%"PRIx64" (%d)" iommufd_backend_invalidate_cache(int iommufd, uint32_t id, uint32_t data_t= ype, uint32_t entry_len, uint32_t entry_num, uint32_t done_num, uint64_t da= ta_ptr, int ret) " iommufd=3D%d id=3D%u data_type=3D%u entry_len=3D%u entry= _num=3D%u done_num=3D%u data_ptr=3D0x%"PRIx64" (%d)" --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297207; cv=none; d=zohomail.com; s=zohoarc; b=i1OjAkrYLMb/5BaQhxW+LVDvtKZoYJsKdRf1fGj0WC1VwcZkPTNoOevkIakOuOOxv/04Jth5irxi7pD3vDY4p/0QWC1IwaQZV5muzvpX7lpEjQ/NRZr1wX2kgt9nWGzL+At2Ry3uDgRKFBwfE+uRcDGlskkJ6ge9KxTamAs82pI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297207; 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=IDUPh26zh3fiGzx4uMZcMc1MoB7a7foGKvF9yAoVct8=; b=gBEh9wH72593BLVDN4/6rv0bNsslUHBSfvO9Fn4SsV0UwAhrZP06k2DMuJWLGsm0tLC+3RWeCsg8vw2CKj0l4QICpS6SHD2DABI3IdC0Z47G63R/a75l+tOxyCByIEkUiFfFV7yzNs0wzND1wLerG4P8/dIWrQImgUoynUyhIoc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297207725209.78743570607674; Tue, 13 Jan 2026 01:40:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfaqu-00032F-1Y; Tue, 13 Jan 2026 04:38:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqm-0002lf-Tu for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaql-0003SF-6B for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:08 -0500 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-638-XtCmZbIMO2ary7GXuBLq6A-1; Tue, 13 Jan 2026 04:38:03 -0500 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 1FA1B19560BB; Tue, 13 Jan 2026 09:38:02 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B18F930001A2; Tue, 13 Jan 2026 09:37:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297086; 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=IDUPh26zh3fiGzx4uMZcMc1MoB7a7foGKvF9yAoVct8=; b=V7ZeNwu55g01PfB5wJ9zx/YVekhXVeku6rzUq+5eh8cIjvfT9GvK1A9I/CHcWlDeR3fJb4 c30+cc7sss73U8whJSXVPWUgc8S7fUPh21A13Du17KwepPlu/5kCyC7DMhtXzKqcfD0lWa 3cpGN/75l/atp2qso2iCk9Mfi5aGkoU= X-MC-Unique: XtCmZbIMO2ary7GXuBLq6A-1 X-Mimecast-MFC-AGG-ID: XtCmZbIMO2ary7GXuBLq6A_1768297082 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , Giovannio Cabiddu , Rohith S R , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 27/41] intel_iommu: Fix unmap_bitmap failure with legacy VFIO backend Date: Tue, 13 Jan 2026 10:36:23 +0100 Message-ID: <20260113093637.1549214-28-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297207967158500 From: Zhenzhong Duan If a VFIO device in guest switches from IOMMU domain to block domain, vtd_address_space_unmap() is called to unmap whole address space. If that happens during migration, migration fails with legacy VFIO backend as below: Status: failed (vfio_container_dma_unmap(0x561bbbd92d90, 0x100000000000, 0x= 100000000000) =3D -7 (Argument list too long)) Because legacy VFIO limits maximum bitmap size to 256MB which maps to 8TB on 4K page system, when 16TB sized UNMAP notification is sent, unmap_bitmap ioctl fails. Normally such large UNMAP notification come from IOVA range rather than system memory. Apart from that, vtd_address_space_unmap() sends UNMAP notification with translated_addr =3D 0, because there is no valid translated_addr for unmapp= ing a whole iommu memory region. This breaks dirty tracking no matter which VFIO backend is used. Fix them all by iterating over DMAMap list to unmap each range with active mapping when global_dirty_tracking is active. global_dirty_tracking is protected by BQL, so it's safe to reference it directly. If it's not active, unmapping the whole address space in one go is optimal. Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu Tested-by: Giovannio Cabiddu Tested-by: Rohith S R Link: https://lore.kernel.org/qemu-devel/20251218062643.624796-7-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index f971cdd14c78fd80df26c0f67d4abc8cfb35645d..bb21ae1743d2bf0dc91c4fc1802= 6f449a290814b 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4764,6 +4764,43 @@ static uint64_t vtd_get_viommu_flags(void *opaque) return flags; } =20 +/* + * There is no valid translated_addr for unmapping a whole iommu memory re= gion. + * When dirty tracking is enabled, we need it to set dirty bitmaps. Iterate + * over DMAMap list to unmap each range with active mapping and translated= _addr + * value. + */ +static void vtd_address_space_unmap_in_dirty_tracking(VTDAddressSpace *as, + IOMMUNotifier *n) +{ + const DMAMap *map; + const DMAMap target =3D { + .iova =3D n->start, + .size =3D n->end, + }; + IOVATree *tree =3D as->iova_tree; + + /* + * DMAMap is created during IOMMU page table sync, it's either 4KB or = huge + * page size and always a power of 2 in size. So the range of DMAMap c= ould + * be used for UNMAP notification directly. + */ + while ((map =3D iova_tree_find(tree, &target))) { + IOMMUTLBEvent event; + + event.type =3D IOMMU_NOTIFIER_UNMAP; + event.entry.iova =3D map->iova; + event.entry.addr_mask =3D map->size; + event.entry.target_as =3D &address_space_memory; + event.entry.perm =3D IOMMU_NONE; + /* This field is needed to set dirty bigmap */ + event.entry.translated_addr =3D map->translated_addr; + memory_region_notify_iommu_one(n, &event); + + iova_tree_remove(tree, *map); + } +} + /* Unmap the whole range in the notifier's scope. */ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) { @@ -4773,6 +4810,11 @@ static void vtd_address_space_unmap(VTDAddressSpace = *as, IOMMUNotifier *n) IntelIOMMUState *s =3D as->iommu_state; DMAMap map; =20 + if (global_dirty_tracking) { + vtd_address_space_unmap_in_dirty_tracking(as, n); + return; + } + /* * Note: all the codes in this function has a assumption that IOVA * bits are no more than VTD_MGAW bits (which is restricted by --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297220; cv=none; d=zohomail.com; s=zohoarc; b=aO74kSGlWmvwNoZqwc1D/A+bk0uvNS/Ci4wAS49cAwFCNw1WPilkVd/c5xA/HmOs+TRW0HOhKOU2hjDQvQUYprQqrTHCS/XLcGtm5/rTPKWFNhmTPihXTlsf9nizIGLWmYIAxbVA1OQ89wvt8ZNrXJS5n82TKByBjz1MZcOY31M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297220; 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=JPjvIaCByeMYDaDwIf1njVRZ5RPCKF+r/m19wytI9As=; b=kqfB+fW0tgE5u85NSynPWpf9EHOacjxCa0f963Lh+MV/fs8Xctfx3nPSD+zj9NrN+8tS5mRzl0SOoyJENA3RcEjXzoZV7HEqu2UOW0hyVgGyrhnN9eb1v79blqM9e0czb+xaS/fBNetzJsoOTJnI1Uuechl+drLMCULSN+MyWEs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297220632540.1124256077736; Tue, 13 Jan 2026 01:40:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfar6-0003Md-5X; Tue, 13 Jan 2026 04:38:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqp-0002vN-7P for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqn-0003Sm-JP for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:10 -0500 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-43-GH91WyNRP4Wy3S0to5W4MQ-1; Tue, 13 Jan 2026 04:38:05 -0500 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 6F5EA19560A3; Tue, 13 Jan 2026 09:38:04 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 75C7330001A8; Tue, 13 Jan 2026 09:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297088; 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=JPjvIaCByeMYDaDwIf1njVRZ5RPCKF+r/m19wytI9As=; b=HiPbwMf6tSdNXmJWW2dbb1AngN7Zk1/roMsXD2gkY+90mnE33yfgZYhYl+hkPCM0Wl/BY1 PELdmFcHkuU79Lxts7lSfMmTSkuD8ZPaHcTwC2eznU1V7zqYkQ6rR+oFKXuyfi4CHa5KUS ZVy4aAy37clVxtwEBAKMdQzeteWaEf8= X-MC-Unique: GH91WyNRP4Wy3S0to5W4MQ-1 X-Mimecast-MFC-AGG-ID: GH91WyNRP4Wy3S0to5W4MQ_1768297084 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Giovannio Cabiddu , Yi Liu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 28/41] vfio/listener: Add missing dirty tracking in region_del Date: Tue, 13 Jan 2026 10:36:24 +0100 Message-ID: <20260113093637.1549214-29-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297222015158500 From: Zhenzhong Duan If a VFIO device in guest switches from passthrough(PT) domain to block domain, the whole memory address space is unmapped, but we passed a NULL iotlb entry to unmap_bitmap, then bitmap query didn't happen and we lost dirty pages. By constructing an iotlb entry with iova =3D gpa for unmap_bitmap, it can set dirty bits correctly. For IOMMU address space, we still send NULL iotlb because VFIO don't know the actual mappings in guest. It's vIOMMU's responsibility to send actual unmapping notifications, e.g., vtd_address_space_unmap_in_dirty_tracking(). Signed-off-by: Zhenzhong Duan Tested-by: Giovannio Cabiddu Reviewed-by: Yi Liu Link: https://lore.kernel.org/qemu-devel/20251218062643.624796-8-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/listener.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 62699cb772d786c1510318dff73973ef4d297177..813621f22f8b5ec284388f9c5f7= 19525ec5f282c 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -713,14 +713,34 @@ static void vfio_listener_region_del(MemoryListener *= listener, =20 if (try_unmap) { bool unmap_all =3D false; + IOMMUTLBEntry entry =3D {}, *iotlb =3D NULL; =20 if (int128_eq(llsize, int128_2_64())) { assert(!iova); unmap_all =3D true; llsize =3D int128_zero(); } + + /* + * Fake an IOTLB entry for identity mapping which is needed by dir= ty + * tracking when switch out of PT domain. In fact, in unmap_bitmap, + * only translated_addr field is used to set dirty bitmap. + * + * Note: When switch into PT domain from DMA domain, the whole IOM= MU + * MR is deleted without iotlb, before that happen, we depend on + * vIOMMU to send unmap notification with accurate iotlb entry to + * VFIO. See vtd_address_space_unmap_in_dirty_tracking() for examp= le, + * it is triggered during switching to block domain because vtd do= es + * not support direct switching from DMA to PT domain. + */ + if (global_dirty_tracking && memory_region_is_ram(section->mr)) { + entry.iova =3D iova; + entry.translated_addr =3D iova; + iotlb =3D &entry; + } + ret =3D vfio_container_dma_unmap(bcontainer, iova, int128_get64(ll= size), - NULL, unmap_all); + iotlb, unmap_all); if (ret) { error_report("vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", " "0x%"HWADDR_PRIx") =3D %d (%s)", --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297131; cv=none; d=zohomail.com; s=zohoarc; b=VaQZQKOLTasV0A5/dmQRtp0WrssOE3mKeqzTPthIQSlUr7eT8Esw7a5mmtG6om+yr2rgXmJzv79RqXzZ57Hkvjd5KSI/sI39mMQ/CHDFWzY68fNj7iUDvCsPkgK+IStvbONPa/bPcQo/hq6y2+WS3Rd/VUjlTspboGJLgwtk/m0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297131; 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=4h/CV9zsXjBGgjswpDw6usjHBVIQlnAhYiqTOwI6vPA=; b=jIVh1XZTBefjZzMk7zRarvrkMpIagchmqrxd4CaCDiunXQ6/a73YCbMCzGiM6JmkTrA09/w/54XY+JqL74KQ4zOpLp9HnzUrK4pcpPKm50PlqcUlWD/c2cv98sCgwyyPTxsjuKneUK0oPHftMtgXO3qBF6V8at145snFShMuAxU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297131679985.1355579770458; Tue, 13 Jan 2026 01:38:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfar3-0003AE-Cm; Tue, 13 Jan 2026 04:38:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqr-0002xD-6Y for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqp-0003T6-MO for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:12 -0500 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-610-JA5Ti87pNR6qai04Pqm-Ng-1; Tue, 13 Jan 2026 04:38:07 -0500 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 CB0D81954231; Tue, 13 Jan 2026 09:38:06 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DFCF03000218; Tue, 13 Jan 2026 09:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297091; 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=4h/CV9zsXjBGgjswpDw6usjHBVIQlnAhYiqTOwI6vPA=; b=SISdBCsrOiTOzIPEjaqHLTXZlsE57DrIHhcRkCiWyFfj9nL4w3DHkmwLcQvp8GcJRtHPBH Yw44ZBZ+S3Oh5ffeQbW/1PJAYfMK9lx//sGQI+Zf3e85FMT3SO68r2ODDCadBwgJYxuCb1 3vcUOpamsF1gJYXjGIY5GJbB/nSfOsc= X-MC-Unique: JA5Ti87pNR6qai04Pqm-Ng-1 X-Mimecast-MFC-AGG-ID: JA5Ti87pNR6qai04Pqm-Ng_1768297086 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 29/41] vfio/migration: Add migration blocker if VM memory is too large to cause unmap_bitmap failure Date: Tue, 13 Jan 2026 10:36:25 +0100 Message-ID: <20260113093637.1549214-30-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297133693158500 From: Zhenzhong Duan With default config, kernel VFIO IOMMU type1 driver limits dirty bitmap to 256MB for unmap_bitmap ioctl so the maximum guest memory region is no more than 8TB size for the ioctl to succeed. Be conservative here to limit total guest memory to max value supported by unmap_bitmap ioctl or else add a migration blocker. IOMMUFD backend doesn't have such limit, one can use it if there is a need to migrate such large VM. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu Link: https://lore.kernel.org/qemu-devel/20251218062643.624796-9-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/migration.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 58a4940b00eb0a070a5a48dc773fe56c42f377cd..e1c25ba90703e9574fdd69275ae= 2705684396697 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -16,6 +16,7 @@ #include =20 #include "system/runstate.h" +#include "hw/core/boards.h" #include "hw/vfio/vfio-device.h" #include "hw/vfio/vfio-migration.h" #include "migration/misc.h" @@ -1152,6 +1153,32 @@ static bool vfio_viommu_preset(VFIODevice *vbasedev) return vbasedev->bcontainer->space->as !=3D &address_space_memory; } =20 +static bool vfio_dirty_tracking_exceed_limit(VFIODevice *vbasedev) +{ + VFIOContainer *bcontainer =3D vbasedev->bcontainer; + uint64_t max_size, page_size; + + if (!bcontainer->dirty_pages_supported) { + return false; + } + + /* + * VFIO IOMMU type1 driver has limitation of bitmap size on unmap_bitm= ap + * ioctl(), calculate the limit and compare with guest memory size to + * catch dirty tracking failure early. + * + * This limit is 8TB with default kernel and QEMU config, we are a bit + * conservative here as VM memory layout may be nonconsecutive or VM + * can run with vIOMMU enabled so the limitation could be relaxed. One + * can also switch to use IOMMUFD backend if there is a need to migrate + * large VM. + */ + page_size =3D 1 << ctz64(bcontainer->dirty_pgsizes); + max_size =3D bcontainer->max_dirty_bitmap_size * BITS_PER_BYTE * page_= size; + + return current_machine->ram_size > max_size; +} + /* * Return true when either migration initialized or blocker registered. * Currently only return false when adding blocker fails which will @@ -1193,6 +1220,13 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Er= ror **errp) goto add_blocker; } =20 + if (vfio_dirty_tracking_exceed_limit(vbasedev)) { + error_setg(&err, "%s: Migration is currently not supported wit= h " + "large memory VM due to dirty tracking limitation i= n " + "backend", vbasedev->name); + goto add_blocker; + } + warn_report("%s: VFIO device doesn't support device and " "IOMMU dirty tracking", vbasedev->name); } --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297189; cv=none; d=zohomail.com; s=zohoarc; b=YAKC0q29/tfrmsUjurcN0j3SDmp97iaeTI3xmzNXZxXbzZXS2xPfkuN+tOgpn/0yLn3Tuz8ufQzoJxoe6edS4tZtadKu3/Bv3FEeJjPVGg3aB67PLdBG/zA2IVzosES4AYNRTjnDYfXgi3vIHI5olmT2hQrm3+chTBdidpF2OvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297189; 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=ONzSRfiSaUWx+KVAPYfPWBlvWLdlYnxCJcldgq2dqbU=; b=B0uE/xerOdy1OPs4K3OsA0vxkjiPKSaymY/GZKauAgHk/gJqGvwzDIvXJ9tYFN0XxLMiDCMxj5jW2pyuMqZK4D+SHEiGsQFoXD9xjATYb8rUzZSvvlw0RiZQ/S6brWCj1FvcjopDSrCzew6E6rqxTC/eJlAKWyAuXokg3I77+Kg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297189069605.3924337266161; Tue, 13 Jan 2026 01:39:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfar8-0003YC-VI; Tue, 13 Jan 2026 04:38:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqx-00039p-EW for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqv-0003Ti-Nb for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:19 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-7CTw0pOKMfC6bf4LDSRQyQ-1; Tue, 13 Jan 2026 04:38:11 -0500 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5252318005B5; Tue, 13 Jan 2026 09:38:10 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 499253000218; Tue, 13 Jan 2026 09:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297097; 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=ONzSRfiSaUWx+KVAPYfPWBlvWLdlYnxCJcldgq2dqbU=; b=RmGFLEAr3NBrJoaQJjKHViWFYktTuHG+OlY4tcT06Kbrf0miPkCebgdNCsRbdx3XDAgyRB 0heEgVZdRs1mAX9LNfoauiE49Xe55qLB43AaojErvl9ZjCgeMcpjdTN0a9hyXOV2S2s72Z ioj4jErNfQ/qUcLAIkZzwIBeyX1jcew= X-MC-Unique: 7CTw0pOKMfC6bf4LDSRQyQ-1 X-Mimecast-MFC-AGG-ID: 7CTw0pOKMfC6bf4LDSRQyQ_1768297090 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Jason Zeng , Joao Martins , Yi Liu , Xudong Hao , Giovannio Cabiddu , Rohith S R , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 30/41] vfio/migration: Allow live migration with vIOMMU without VFs using device dirty tracking Date: Tue, 13 Jan 2026 10:36:26 +0100 Message-ID: <20260113093637.1549214-31-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297189943158500 From: Zhenzhong Duan Commit e46883204c38 ("vfio/migration: Block migration with vIOMMU") introduces a migration blocker when vIOMMU is enabled, because we need to calculate the IOVA ranges for device dirty tracking. But this is unnecessary for iommu dirty tracking. Limit the vfio_viommu_preset() check to those devices which use device dirty tracking. This allows live migration with VFIO devices which use iommu dirty tracking. Suggested-by: Jason Zeng Co-developed-by: Joao Martins Signed-off-by: Joao Martins Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu Tested-by: Xudong Hao Tested-by: Giovannio Cabiddu Tested-by: Rohith S R Link: https://lore.kernel.org/qemu-devel/20251218062643.624796-10-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-device.h | 10 ++++++++++ hw/vfio/container.c | 5 +---- hw/vfio/device.c | 6 ++++++ hw/vfio/migration.c | 6 +++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 0bc877ff62f9473d49782ce7c2ee1eb943175821..48d00c7bc47a2fd11a522a1ad09= b051f16342545 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -148,6 +148,16 @@ bool vfio_device_irq_set_signaling(VFIODevice *vbasede= v, int index, int subindex =20 void vfio_device_reset_handler(void *opaque); bool vfio_device_is_mdev(VFIODevice *vbasedev); +/** + * vfio_device_dirty_pages_disabled: Check if device dirty tracking will be + * used for a VFIO device + * + * @vbasedev: The VFIODevice to transform + * + * Return: true if either @vbasedev doesn't support device dirty tracking = or + * is forcedly disabled from command line, otherwise false. + */ +bool vfio_device_dirty_pages_disabled(VFIODevice *vbasedev); bool vfio_device_hiod_create_and_realize(VFIODevice *vbasedev, const char *typename, Error **err= p); bool vfio_device_attach(char *name, VFIODevice *vbasedev, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 9881f5df2cc34262ae6aa88aa937659e7b197cd2..af16cd14db069882cc5fcf6349b= 433af3867f40c 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -178,10 +178,7 @@ bool vfio_container_devices_dirty_tracking_is_supporte= d( VFIODevice *vbasedev; =20 QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { - if (vbasedev->device_dirty_page_tracking =3D=3D ON_OFF_AUTO_OFF) { - return false; - } - if (!vbasedev->dirty_pages_supported) { + if (vfio_device_dirty_pages_disabled(vbasedev)) { return false; } } diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 100532f35d9ad14bf14c8d6d783f7b06aa85245a..3bab082322633f7cbd4295b4e91= 717c83fbb48da 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -412,6 +412,12 @@ bool vfio_device_is_mdev(VFIODevice *vbasedev) return subsys && (strcmp(subsys, "/sys/bus/mdev") =3D=3D 0); } =20 +bool vfio_device_dirty_pages_disabled(VFIODevice *vbasedev) +{ + return (!vbasedev->dirty_pages_supported || + vbasedev->device_dirty_page_tracking =3D=3D ON_OFF_AUTO_OFF); +} + bool vfio_device_hiod_create_and_realize(VFIODevice *vbasedev, const char *typename, Error **err= p) { diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index e1c25ba90703e9574fdd69275ae2705684396697..f857dc25ed4d0f824bdabc16822= 8a5e925ac7dbe 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1210,8 +1210,7 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Err= or **errp) return !vfio_block_migration(vbasedev, err, errp); } =20 - if ((!vbasedev->dirty_pages_supported || - vbasedev->device_dirty_page_tracking =3D=3D ON_OFF_AUTO_OFF) && + if (vfio_device_dirty_pages_disabled(vbasedev) && !vbasedev->iommu_dirty_tracking) { if (vbasedev->enable_migration =3D=3D ON_OFF_AUTO_AUTO) { error_setg(&err, @@ -1236,7 +1235,8 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Err= or **errp) goto out_deinit; } =20 - if (vfio_viommu_preset(vbasedev)) { + if (!vfio_device_dirty_pages_disabled(vbasedev) && + vfio_viommu_preset(vbasedev)) { error_setg(&err, "%s: Migration is currently not supported " "with vIOMMU enabled", vbasedev->name); goto add_blocker; --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297134; cv=none; d=zohomail.com; s=zohoarc; b=Hqy8W0vfZ6S/ddDhlkj8pmvFRgFkbL0h1WdMX4oyK75rU0oDuSMwCeOS1NXSZR6JQrlGdZNn/IVxDEmOcjj8AH6FzZYWJolYVBmg2bvctg9jRoveFeRrVrc614PViX9oCQ1tuYtcycVUDEXbYbQJKb/aQHyhJv5eXpRB7vzrkfY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297134; 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=acIPCCq6BYTz03H6ermtQrrs5LawRKp9JbbGzGgjjWw=; b=ByAebFYimmWXetxqIMZtz00T1qw2KjoodwrNxmeNhbU/mqfuDv5ubkcYwSaAyXdbvelBr6jWwOCD3voKFOKIrf6rDHI13K+Awcm57tG6ez07w8YIxahOW8HUnyQNJsncl5v7aE9vR1z7Py8w27WMGLQkZ4L8BlE/5qBAxuyojBg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297134170879.8176039365668; Tue, 13 Jan 2026 01:38:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfar7-0003V4-Bp; Tue, 13 Jan 2026 04:38:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqx-00039l-7Z for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqv-0003Tg-Im for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:18 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-425-DO_1QOLMOdu8MFh9GVKpUQ-1; Tue, 13 Jan 2026 04:38:14 -0500 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ED06618005AD; Tue, 13 Jan 2026 09:38:12 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C437B30001A2; Tue, 13 Jan 2026 09:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297096; 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=acIPCCq6BYTz03H6ermtQrrs5LawRKp9JbbGzGgjjWw=; b=ieI1+M2Kcxbm4nCsWFafy2SZBBf1GwGmpba3pCYT7bKgA7FiKl6gJHNkVcYI0EUy5NjPOR NX7h3CDbd8h71TjBRgu5YoDWZcvQN4ORIzw59YjvQFvHUPGG/6yvS2jZScElGLYp3cjw0G 2irMIgjJDVM6F4iLtV7qoc/LQgYEuJ0= X-MC-Unique: DO_1QOLMOdu8MFh9GVKpUQ-1 X-Mimecast-MFC-AGG-ID: DO_1QOLMOdu8MFh9GVKpUQ_1768297093 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Eric Auger , Nicolin Chen , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 31/41] hw/pci: Introduce pci_device_get_host_iommu_quirks() Date: Tue, 13 Jan 2026 10:36:27 +0100 Message-ID: <20260113093637.1549214-32-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297135716158500 From: Zhenzhong Duan In VFIO core, we call iommufd_backend_get_device_info() to return vendor specific hardware information data, but it's not good to retrieve this raw data in VFIO core. Introduce a new PCIIOMMUOps optional callback, get_host_iommu_quirk() which allows to retrieve the vendor specific hardware information data and convert it into bitmaps defined with enum host_iommu_quirks. pci_device_get_host_iommu_quirks() is a wrapper that can be called on a PCI device potentially protected by a vIOMMU. Suggested-by: Eric Auger Suggested-by: Nicolin Chen Signed-off-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20260106062808.316574-2-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/core/iommu.h | 5 +++++ include/hw/pci/pci.h | 31 +++++++++++++++++++++++++++++++ hw/pci/pci.c | 12 ++++++++++++ 3 files changed, 48 insertions(+) diff --git a/include/hw/core/iommu.h b/include/hw/core/iommu.h index fcbbcd10150e6e675fb68c817e786bf23b301892..d5401a397b2a47d0cf782462328= 28c93b6392b71 100644 --- a/include/hw/core/iommu.h +++ b/include/hw/core/iommu.h @@ -22,4 +22,9 @@ enum viommu_flags { VIOMMU_FLAG_WANT_NESTING_PARENT =3D BIT_ULL(0), }; =20 +/* Host IOMMU quirks. Extracted from host IOMMU capabilities */ +enum host_iommu_quirks { + HOST_IOMMU_QUIRK_NESTING_PARENT_BYPASS_RO =3D BIT_ULL(0), +}; + #endif /* HW_IOMMU_H */ diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 868817cc05ae26832246269eb4a1637c8e6ae64b..6fd8984c99088906fcac73c1f95= d2c7f84380c4e 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -474,6 +474,23 @@ typedef struct PCIIOMMUOps { * enum viommu_flags. */ uint64_t (*get_viommu_flags)(void *opaque); + /** + * @get_host_iommu_quirks: get host IOMMU quirks + * + * Optional callback, if not implemented, then vIOMMU doesn't support + * converting @type specific hardware information data into a standard + * bitmap format. + * + * @type: IOMMU hardware info type + * + * @caps: IOMMU @type specific hardware information data + * + * @size: size of @caps + * + * Returns: bitmap with each bit representing a host IOMMU quirk defin= ed in + * enum host_iommu_quirks + */ + uint64_t (*get_host_iommu_quirks)(uint32_t type, void *caps, uint32_t = size); /** * @get_iotlb_info: get properties required to initialize a device IOT= LB. * @@ -666,6 +683,20 @@ void pci_device_unset_iommu_device(PCIDevice *dev); */ uint64_t pci_device_get_viommu_flags(PCIDevice *dev); =20 +/** + * pci_device_get_host_iommu_quirks: get host IOMMU quirks. + * + * Returns: bitmap with each bit representing a host IOMMU quirk defined in + * enum host_iommu_quirks. Or 0 if vIOMMU doesn't convert any. + * + * @dev: PCI device pointer. + * @type: IOMMU hardware info type + * @caps: IOMMU @type specific hardware information data + * @size: size of @caps + */ +uint64_t pci_device_get_host_iommu_quirks(PCIDevice *dev, uint32_t type, + void *caps, uint32_t size); + /** * pci_iommu_get_iotlb_info: get properties required to initialize a * device IOTLB. diff --git a/hw/pci/pci.c b/hw/pci/pci.c index a136e772a39fd3fb1b3631351dbea710227bedfe..8cbf5f5d703847166c94aaae4d1= d5f33c3dc1def 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -3032,6 +3032,18 @@ uint64_t pci_device_get_viommu_flags(PCIDevice *dev) return 0; } =20 +uint64_t pci_device_get_host_iommu_quirks(PCIDevice *dev, uint32_t type, + void *caps, uint32_t size) +{ + PCIBus *iommu_bus; + + pci_device_get_iommu_bus_devfn(dev, &iommu_bus, NULL, NULL); + if (iommu_bus && iommu_bus->iommu_ops->get_host_iommu_quirks) { + return iommu_bus->iommu_ops->get_host_iommu_quirks(type, caps, siz= e); + } + return 0; +} + int pci_pri_request_page(PCIDevice *dev, uint32_t pasid, bool priv_req, bool exec_req, hwaddr addr, bool lpig, uint16_t prgi, bool is_read, bool is_write) --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297351; cv=none; d=zohomail.com; s=zohoarc; b=TGw/pHECeMIijYyXYQC4F79auc1bjh81/eT0NLKO3suBWCdz9Fjm5SQ522y6rtucZ+uKPF2b0YwE52CjeOTSBby0aM7pTnmpne0GjYAEnar8/qI7a2Hb9D0SQGSbAlLU3oVbOvo5ZHHxOA4JWDtISqpgXFuWCnRNbkMqA5+ef3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297351; 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=+0UF7ynqYRkpmQCabpzEd+x3V7/Hjn5OOWN/GopW2PE=; b=IGSvUOVvfQ1pnjVDrEzrF8KzJyWPAEBon6kz08srTwHyCQUx7kSLkxx2f12BOMP1rs6btS41kcU7ZGQjNde8h6BChTKPM8/kWewZUZB2wYQAa3CDrKLQFVCBMCwDGiF69SPStd1c1m1+4rJu/+agRDozILgiYJRO/Xqk+Z6ATW4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297351167415.4497559026811; Tue, 13 Jan 2026 01:42:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfarX-0004KT-4e; Tue, 13 Jan 2026 04:38:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar0-0003Ck-L9 for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqz-0003U4-0c for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:22 -0500 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-329-9j9WU-usNH2VbzMjBU6Bkw-1; Tue, 13 Jan 2026 04:38:16 -0500 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 4880F1956088; Tue, 13 Jan 2026 09:38:15 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 52C2A30001A2; Tue, 13 Jan 2026 09:38:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297099; 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=+0UF7ynqYRkpmQCabpzEd+x3V7/Hjn5OOWN/GopW2PE=; b=KSO1qANdr8Ef47cTgDwi2AlId/SiZdCA4zqW+qwx70MakrEUgyl1yyobHxSvYjXFyAFZHL 8pOkbi6Z9YrPbYNN3G764aRUoWH/Z5SP2E8MegcwJ3TQ4Eh1eh+IVzGJGHF8/7Qg+w89Fn Dy4NzynGKtU6y87dZ+AMDdsizZdd4v0= X-MC-Unique: 9j9WU-usNH2VbzMjBU6Bkw-1 X-Mimecast-MFC-AGG-ID: 9j9WU-usNH2VbzMjBU6Bkw_1768297095 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Eric Auger , Nicolin Chen , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 32/41] intel_iommu_accel: Implement get_host_iommu_quirks() callback Date: Tue, 13 Jan 2026 10:36:28 +0100 Message-ID: <20260113093637.1549214-33-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297352533158500 From: Zhenzhong Duan Implement get_host_iommu_quirks() callback to retrieve the vendor specific hardware information data and convert it into bitmaps defined with enum host_iommu_quirks. It will be used by VFIO in subsequent patch. Suggested-by: Eric Auger Suggested-by: Nicolin Chen Signed-off-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20260106062808.316574-3-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/intel_iommu_accel.h | 5 +++++ hw/i386/intel_iommu.c | 2 ++ hw/i386/intel_iommu_accel.c | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 6dec8788f18d0196550b3d0047dc5a5b29ed2c6b..e5f0b077b4b9ab7a58796107e78= ab8a7d0a0bd20 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -20,6 +20,7 @@ bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, E= rror **errp); void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_= id, uint32_t pasid, hwaddr addr, uint64_t npages, bool ih); +void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, @@ -47,5 +48,9 @@ static inline void vtd_flush_host_piotlb_all_locked(Intel= IOMMUState *s, uint64_t npages, bool = ih) { } + +static inline void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops) +{ +} #endif #endif diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index bb21ae1743d2bf0dc91c4fc18026f449a290814b..e8a6f50a5a03e71b5f6025dce5f= 9510e0a31f020 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -5590,6 +5590,8 @@ static void vtd_class_init(ObjectClass *klass, const = void *data) x86_class->int_remap =3D vtd_int_remap; set_bit(DEVICE_CATEGORY_MISC, dc->categories); dc->desc =3D "Intel IOMMU (VT-d) DMA Remapping device"; + + vtd_iommu_ops_update_accel(&vtd_iommu_ops); } =20 static const TypeInfo vtd_info =3D { diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 250232b5a979e9b34d161fde554fd0c64b0cd3d9..67d54849f2f08187629fca5e2c0= 81f8dd003b6b2 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -12,6 +12,7 @@ #include "system/iommufd.h" #include "intel_iommu_internal.h" #include "intel_iommu_accel.h" +#include "hw/core/iommu.h" #include "hw/pci/pci_bus.h" #include "trace.h" =20 @@ -249,3 +250,23 @@ void vtd_flush_host_piotlb_all_locked(IntelIOMMUState = *s, uint16_t domain_id, g_hash_table_foreach(s->vtd_address_spaces, vtd_flush_host_piotlb_locked, &piotlb_info); } + +static uint64_t vtd_get_host_iommu_quirks(uint32_t type, + void *caps, uint32_t size) +{ + struct iommu_hw_info_vtd *vtd =3D caps; + uint64_t quirks =3D 0; + + if (type =3D=3D IOMMU_HW_INFO_TYPE_INTEL_VTD && + sizeof(struct iommu_hw_info_vtd) <=3D size && + vtd->flags & IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17) { + quirks |=3D HOST_IOMMU_QUIRK_NESTING_PARENT_BYPASS_RO; + } + + return quirks; +} + +void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops) +{ + ops->get_host_iommu_quirks =3D vtd_get_host_iommu_quirks; +} --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297223; cv=none; d=zohomail.com; s=zohoarc; b=DSL054wmppeB81woWpKxMs0Gg3t6c2EPnxY2bHZzk/v7y8BZNaJwrCIk8nRt0RujnTcMt+Ekz0pl9sJZKh0cwV/UBqnLfvq6rcP2XKio4ArIvRlGxgSPCesNR9uYkCUmKNWtpT2Y70iHCitBHtPHjv60tSv5hxA1/aRJz5wTsDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297223; 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=3vjfMWroBwbRuDbaxuV3pc5DM8ekaFeG0lGHDNirnPw=; b=Ls/AZAaGqfXhlvm4Wv7MEknJZA0qJHZ5hu880qRz2Da/U8kmYNvA9tSkAWtFXiQUChLcP2owCkuCHHSCFQaxrTYmQwGPUHbU9Cee0exf0yBX85EWmPifPITq/8nMuyyXAg+t3wThUmktODmAv0UiDaEFaFFIOQw4X9Wyi59XF9Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297223281163.8011972661492; Tue, 13 Jan 2026 01:40:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfarI-0003pG-Mm; Tue, 13 Jan 2026 04:38:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar0-0003Cm-Qh for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfaqz-0003UA-0M for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:22 -0500 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-336-MDk5YS8sMFiC-QDE-tk12Q-1; Tue, 13 Jan 2026 04:38:18 -0500 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 5AE1C19560B2; Tue, 13 Jan 2026 09:38:17 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BA14230001A8; Tue, 13 Jan 2026 09:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297099; 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=3vjfMWroBwbRuDbaxuV3pc5DM8ekaFeG0lGHDNirnPw=; b=Aqg7snEIJnnhhdeXODRYUfJILmnFV9pXT7owtkU71g52E0pgbsturTz3da/aTjQkLccYWO uvwKs7nLVObNt4erljRJ85J/hkwUdbzw6MqyULeveWoX/dhj9p077x0x0zBbXIKlPl+tCj 9FVQ29li9j9r3c5DIxT4rbeDs9hSQXQ= X-MC-Unique: MDk5YS8sMFiC-QDE-tk12Q-1 X-Mimecast-MFC-AGG-ID: MDk5YS8sMFiC-QDE-tk12Q_1768297097 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?= Subject: [PULL 33/41] vfio/listener: Bypass readonly region for dirty tracking Date: Tue, 13 Jan 2026 10:36:29 +0100 Message-ID: <20260113093637.1549214-34-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297239227158500 From: Zhenzhong Duan When doing dirty tracking or calculating dirty tracking range, readonly regions can be bypassed, because corresponding DMA mappings are readonly and never become dirty. This can optimize dirty tracking a bit for passthrough device. Signed-off-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20260106062808.316574-4-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/listener.c | 48 ++++++++++++++++++++++++++++++++++---------- hw/vfio/trace-events | 1 + 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 813621f22f8b5ec284388f9c5f719525ec5f282c..f193468dee30354ea8c07e9bf2d= 89b4da42ab78a 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -76,8 +76,13 @@ static bool vfio_log_sync_needed(const VFIOContainer *bc= ontainer) return true; } =20 -static bool vfio_listener_skipped_section(MemoryRegionSection *section) +static bool vfio_listener_skipped_section(MemoryRegionSection *section, + bool bypass_ro) { + if (bypass_ro && section->readonly) { + return true; + } + return (!memory_region_is_ram(section->mr) && !memory_region_is_iommu(section->mr)) || memory_region_is_protected(section->mr) || @@ -368,9 +373,9 @@ static bool vfio_known_safe_misalignment(MemoryRegionSe= ction *section) } =20 static bool vfio_listener_valid_section(MemoryRegionSection *section, - const char *name) + bool bypass_ro, const char *name) { - if (vfio_listener_skipped_section(section)) { + if (vfio_listener_skipped_section(section, bypass_ro)) { trace_vfio_listener_region_skip(name, section->offset_within_address_space, section->offset_within_address_space + @@ -497,7 +502,7 @@ void vfio_container_region_add(VFIOContainer *bcontaine= r, int ret; Error *err =3D NULL; =20 - if (!vfio_listener_valid_section(section, "region_add")) { + if (!vfio_listener_valid_section(section, false, "region_add")) { return; } =20 @@ -663,7 +668,7 @@ static void vfio_listener_region_del(MemoryListener *li= stener, int ret; bool try_unmap =3D true; =20 - if (!vfio_listener_valid_section(section, "region_del")) { + if (!vfio_listener_valid_section(section, false, "region_del")) { return; } =20 @@ -722,9 +727,10 @@ static void vfio_listener_region_del(MemoryListener *l= istener, } =20 /* - * Fake an IOTLB entry for identity mapping which is needed by dir= ty - * tracking when switch out of PT domain. In fact, in unmap_bitmap, - * only translated_addr field is used to set dirty bitmap. + * Fake an IOTLB entry for writable identity mapping which is need= ed + * by dirty tracking when switch out of PT domain. In fact, in + * unmap_bitmap, only translated_addr field is used to set dirty + * bitmap. * * Note: When switch into PT domain from DMA domain, the whole IOM= MU * MR is deleted without iotlb, before that happen, we depend on @@ -733,7 +739,8 @@ static void vfio_listener_region_del(MemoryListener *li= stener, * it is triggered during switching to block domain because vtd do= es * not support direct switching from DMA to PT domain. */ - if (global_dirty_tracking && memory_region_is_ram(section->mr)) { + if (global_dirty_tracking && memory_region_is_ram(section->mr) && + !section->readonly) { entry.iova =3D iova; entry.translated_addr =3D iova; iotlb =3D &entry; @@ -841,7 +848,8 @@ static void vfio_dirty_tracking_update(MemoryListener *= listener, container_of(listener, VFIODirtyRangesListener, listener); hwaddr iova, end; =20 - if (!vfio_listener_valid_section(section, "tracking_update") || + /* Bypass readonly section as it never becomes dirty */ + if (!vfio_listener_valid_section(section, true, "tracking_update") || !vfio_get_section_iova_range(dirty->bcontainer, section, &iova, &end, NULL)) { return; @@ -1100,6 +1108,19 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifie= r *n, IOMMUTLBEntry *iotlb) if (!mr) { goto out_unlock; } + + /* + * The mapping is readonly when either it's a readonly mapping in guest + * or mapped target is readonly, bypass it for dirty tracking as it + * never becomes dirty. + */ + if (!(iotlb->perm & IOMMU_WO) || mr->readonly) { + trace_vfio_iommu_map_dirty_notify_skip_ro(iova, + iova + iotlb->addr_mask); + rcu_read_unlock(); + return; + } + translated_addr =3D memory_region_get_ram_addr(mr) + xlat; =20 ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, iotlb->add= r_mask + 1, @@ -1235,7 +1256,12 @@ static void vfio_listener_log_sync(MemoryListener *l= istener, int ret; Error *local_err =3D NULL; =20 - if (vfio_listener_skipped_section(section)) { + /* + * Bypass readonly section as it never becomes dirty, iommu memory sec= tion + * is RW and never bypassed. The readonly mappings in iommu MR are byp= assed + * in vfio_iommu_map_dirty_notify(). + */ + if (vfio_listener_skipped_section(section, true)) { return; } =20 diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 3c62bab7647a7d027038444fa4b164182d3feb2b..180e3d526b80bd43d18bbfb9332= 833df4fbeb720 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -103,6 +103,7 @@ vfio_listener_region_del(uint64_t start, uint64_t end) = "region_del 0x%"PRIx64" - vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t m= in, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64"= - 0x%"PRIx64"]" vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t m= ax32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci) "nr= _ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"], = pci64:[0x%"PRIx64" - 0x%"PRIx64"]" vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 +vfio_iommu_map_dirty_notify_skip_ro(uint64_t iova_start, uint64_t iova_end= ) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64 =20 # container.c vfio_container_query_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t b= ackend_flag, uint64_t bitmap_size, uint64_t translated_addr, uint64_t dirty= _pages) "iova=3D0x%"PRIx64" size=3D0x%"PRIx64" backend_flag=3D0x%"PRIx64" b= itmap_size=3D0x%"PRIx64" gpa=3D0x%"PRIx64" dirty_pages=3D%"PRIu64 --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297166; cv=none; d=zohomail.com; s=zohoarc; b=LRVxa0FCI/pJTciv8cyHvGMwK0NAv+Ch5344iZ98h6ILR/LNIitb7YWJ0YiVx0pjiUCfqPU9lC4K7MtBXufmtt7EJijtG7oONjVOeNvTegA4k/S5nTZJzD/VvtN7suQUnRofW7lKWiUknzdNuAgbpzdPKrp8FUKgJ9jzG0eWpwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297166; 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=E+c0XSB3dj7G1jIOFSH8sQhzUXIiY/x0fc8xkAVaulg=; b=dValjSFL8PN2iqQH17CH5DIX9rcWqQRJlgculymtRLt9TLu44ZPpX+qF/AWt0QETsFD3+GSvE9eEC1zrYSJRG/1fqRovlADvSKLgZWs6IzKAVtBRgR1yvgh/gaj1OS6KtJYPczwGv5TwGoKq+gDRxY1+joow7DWvN3c/oJztBFU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297166184871.5351783458618; Tue, 13 Jan 2026 01:39:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfarS-0003yf-Rh; Tue, 13 Jan 2026 04:38:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar2-0003FN-PT for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar0-0003UN-Ko for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:24 -0500 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-25-_xAe-mGkNJGi2U5wmNkwkw-1; Tue, 13 Jan 2026 04:38:20 -0500 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 503B919560A2; Tue, 13 Jan 2026 09:38:19 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CB5CA30001A2; Tue, 13 Jan 2026 09:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297102; 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=E+c0XSB3dj7G1jIOFSH8sQhzUXIiY/x0fc8xkAVaulg=; b=J014SdbGDdkHXVjQd2NcH7jKXLc/6+cnqC4eO+gvl6XxmaEqu3OUbV2pwd7NSZhni8qclr QSZzNjJdHlF6/3+D4yo18tMfZxYr57dvjWyxfyGggvZB5nqxKVQv+pi2MII/apXtdubivZ h8WImu22DV7CP1g+6waNgpbtsF26tEU= X-MC-Unique: _xAe-mGkNJGi2U5wmNkwkw-1 X-Mimecast-MFC-AGG-ID: _xAe-mGkNJGi2U5wmNkwkw_1768297099 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?= Subject: [PULL 34/41] Workaround for ERRATA_772415_SPR17 Date: Tue, 13 Jan 2026 10:36:30 +0100 Message-ID: <20260113093637.1549214-35-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297167875158500 From: Zhenzhong Duan On a system influenced by ERRATA_772415, IOMMU_HW_INFO_VTD_ERRATA_772415_SP= R17 is repored by IOMMU_DEVICE_GET_HW_INFO. Due to this errata, even the readon= ly range mapped on second stage page table could still be written. Reference from 4th Gen Intel Xeon Processor Scalable Family Specification Update, Errata Details, SPR17. Link https://edc.intel.com/content/www/us/en/design/products-and-solutions/= processors-and-chipsets/eagle-stream/sapphire-rapids-specification-update/ Backup https://cdrdv2.intel.com/v1/dl/getContent/772415 Also copied the SPR17 details from above link: "Problem: When remapping hardware is configured by system software in scalable mode as Nested (PGTT=3D011b) and with PWSNP field Set in the PASID-table-entry, it may Set Accessed bit and Dirty bit (and Extended Access bit if enabled) in first-stage page-table entries even when second-stage mappings indicate that corresponding first-stage page-table is Read-Only. Implication: Due to this erratum, pages mapped as Read-only in second-stage page-tables may be modified by remapping hardware Access/Dirty bit updates. Workaround: None identified. System software enabling nested translations for a VM should ensure that there are no read-only pages in the corresponding second-stage mappings." Introduce a helper vfio_device_get_host_iommu_quirk_bypass_ro to check if readonly mappings should be bypassed. Signed-off-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20260106062808.316574-5-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- docs/devel/vfio-iommufd.rst | 9 +++++++++ include/hw/vfio/vfio-container.h | 1 + include/hw/vfio/vfio-device.h | 3 +++ hw/vfio/device.c | 14 ++++++++++++++ hw/vfio/iommufd.c | 9 ++++++++- hw/vfio/listener.c | 6 ++++-- 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/docs/devel/vfio-iommufd.rst b/docs/devel/vfio-iommufd.rst index 2d6e60dce1d38f1de136c3d65f3c396aef9e0805..6928b47643b876df51675e7607e= dca62435de139 100644 --- a/docs/devel/vfio-iommufd.rst +++ b/docs/devel/vfio-iommufd.rst @@ -169,3 +169,12 @@ otherwise below error shows: .. code-block:: none =20 qemu-system-x86_64: -device vfio-pci,host=3D0000:02:00.0,bus=3Dbridge1= ,iommufd=3Diommufd0: vfio 0000:02:00.0: Failed to set vIOMMU: Host device d= ownstream to a PCI bridge is unsupported when x-flts=3Don + +If host IOMMU has ERRATA_772415_SPR17, running guest with "intel_iommu=3Do= n,sm_off" +is unsupported, kexec or reboot guest from "intel_iommu=3Don,sm_on" to +"intel_iommu=3Don,sm_off" is also unsupported. Configure scalable mode off= as +below if it's not needed by guest: + +.. code-block:: bash + + -device intel-iommu,x-scalable-mode=3Doff diff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-contai= ner.h index 9f6e8cedfc9541e84558d74bdb156e4963a68639..a7d5c5ed679a0338937ae02f371= 40d94720f6f11 100644 --- a/include/hw/vfio/vfio-container.h +++ b/include/hw/vfio/vfio-container.h @@ -52,6 +52,7 @@ struct VFIOContainer { QLIST_HEAD(, VFIODevice) device_list; GList *iova_ranges; NotifierWithReturn cpr_reboot_notifier; + bool bypass_ro; }; =20 #define TYPE_VFIO_IOMMU "vfio-iommu" diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 48d00c7bc47a2fd11a522a1ad09b051f16342545..f6f3d0e3786cf85553d75674828= 391e16f9fa250 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -268,6 +268,9 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOCont= ainer *bcontainer, void vfio_device_unprepare(VFIODevice *vbasedev); =20 bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev); +bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODevice *vbasedev, + uint32_t type, void *caps, + uint32_t size); =20 int vfio_device_get_region_info(VFIODevice *vbasedev, int index, struct vfio_region_info **info); diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 3bab082322633f7cbd4295b4e91717c83fbb48da..086f20f6762a3a86f52bbab840e= f67f603850a01 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -533,6 +533,20 @@ bool vfio_device_get_viommu_flags_want_nesting(VFIODev= ice *vbasedev) return false; } =20 +bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODevice *vbasedev, + uint32_t type, void *caps, + uint32_t size) +{ + VFIOPCIDevice *vdev =3D vfio_pci_from_vfio_device(vbasedev); + + if (vdev) { + return !!(pci_device_get_host_iommu_quirks(PCI_DEVICE(vdev), type, + caps, size) & + HOST_IOMMU_QUIRK_NESTING_PARENT_BYPASS_RO); + } + return false; +} + /* * Traditional ioctl() based io */ diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 0bf68620d2c9a7a5e21553b9cc275e627b73327f..2947e1b80f5213d2781a32cb669= bf3b66b69a643 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -351,6 +351,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, VFIOContainer *bcontainer =3D VFIO_IOMMU(container); uint32_t type, flags =3D 0; uint64_t hw_caps; + VendorCaps caps; VFIOIOASHwpt *hwpt; uint32_t hwpt_id; int ret; @@ -396,7 +397,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, * instead. */ if (!iommufd_backend_get_device_info(vbasedev->iommufd, vbasedev->devi= d, - &type, NULL, 0, &hw_caps, errp)) { + &type, &caps, sizeof(caps), &hw_c= aps, + errp)) { return false; } =20 @@ -411,6 +413,11 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, */ if (vfio_device_get_viommu_flags_want_nesting(vbasedev)) { flags |=3D IOMMU_HWPT_ALLOC_NEST_PARENT; + + if (vfio_device_get_host_iommu_quirk_bypass_ro(vbasedev, type, + &caps, sizeof(caps)= )) { + bcontainer->bypass_ro =3D true; + } } =20 if (cpr_is_incoming()) { diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index f193468dee30354ea8c07e9bf2d89b4da42ab78a..8ba1cd255d146ab8055ab73c71e= ac640eafa1bdd 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -502,7 +502,8 @@ void vfio_container_region_add(VFIOContainer *bcontaine= r, int ret; Error *err =3D NULL; =20 - if (!vfio_listener_valid_section(section, false, "region_add")) { + if (!vfio_listener_valid_section(section, bcontainer->bypass_ro, + "region_add")) { return; } =20 @@ -668,7 +669,8 @@ static void vfio_listener_region_del(MemoryListener *li= stener, int ret; bool try_unmap =3D true; =20 - if (!vfio_listener_valid_section(section, false, "region_del")) { + if (!vfio_listener_valid_section(section, bcontainer->bypass_ro, + "region_del")) { return; } =20 --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297173; cv=none; d=zohomail.com; s=zohoarc; b=jkCrGnuFVWWzq1N9AvRUEeVJVkz1sATA2kGLYqmtspqzNnZrxt1K1RrGEO+mm4PvcJpWVoj8fl73V8t4IombxaEJ/OfLHj3+mnkOQqqvsm+wuiKcmab7oLlYoEOEoWQ4t7MZOc6FU4t9+Q6eI6ufKbPQ/9ESyBKDAgrSnJZUmFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297173; 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=5ngXbfZKk15+ACRyo+DnfXhdDtH8HlbsllMkfeSzSIU=; b=g/IitQyv5Ir9tu2gSTBhJGYL/Zm+lOBw+jVov3JWOhebSNBg6O7NbrdYQztqLfxPXeDCIqKtIzbHtf9UZ4lcGC2jZJ0E7OFrtbVmv6wRoycjCH23aBYiUL3SeDfFxrA4MBYlFpmQzbKawmjb899Z1FG3bjJgLNr2p4hpizlPPxw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297173137633.2078830756515; Tue, 13 Jan 2026 01:39:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfarE-0003mg-Sc; Tue, 13 Jan 2026 04:38:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar4-0003HC-Vy for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar2-0003Uk-Iy for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:26 -0500 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-439-DFFv6Ls5OOaWCHiQJgIlrQ-1; Tue, 13 Jan 2026 04:38:22 -0500 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 43B0C195609D; Tue, 13 Jan 2026 09:38:21 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C073C30001A2; Tue, 13 Jan 2026 09:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297103; 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=5ngXbfZKk15+ACRyo+DnfXhdDtH8HlbsllMkfeSzSIU=; b=gZL2s6AyDoSgYGe0WuzeZS0/XUtGrzwQ8MrgpIHocIRxx0haY8CNFxNW2K4kLG1AtdIuF0 dhJ32t27IjTc5NJI+l9Tjlg7jBflS2hdS/oJhOX9mJ8wRuQYzWKAmvxkTfb3H2oGIg9NWw eSc5YCBmsGcORIBMYOrqSdDMvvj/pxk= X-MC-Unique: DFFv6Ls5OOaWCHiQJgIlrQ-1 X-Mimecast-MFC-AGG-ID: DFFv6Ls5OOaWCHiQJgIlrQ_1768297101 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Farhan Ali , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 35/41] util/vfio-helper: Fix endianness in PCI config read/write functions Date: Tue, 13 Jan 2026 10:36:31 +0100 Message-ID: <20260113093637.1549214-36-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297173840158500 From: Farhan Ali The VFIO pread/pwrite functions use little-endian data format. Currently, t= he qemu_vfio_pci_read_config() and qemu_vfio_pci_write_config() don't correctly convert from CPU native endian format to little-endian (and vice versa) when using the pread/pwrite functions. Fix this by limiting read/write to 32 bits and handling endian conversion in qemu_vfio_pci_read_config() and qemu_vfio_pci_write_config(). Signed-off-by: Farhan Ali Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20260105222029.2423-1-alifm@linux.= ibm.com [ clg: Fixed typo in subject ] Signed-off-by: C=C3=A9dric Le Goater --- util/vfio-helpers.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index c6195161637a16b4f26dc82f0297e43281a717f7..aab0bf9d485d41b7dc41a1e4644= 9060777cca5e2 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -233,31 +233,36 @@ int qemu_vfio_pci_init_irq(QEMUVFIOState *s, EventNot= ifier *e, return 0; } =20 -static int qemu_vfio_pci_read_config(QEMUVFIOState *s, void *buf, +static int qemu_vfio_pci_read_config(QEMUVFIOState *s, uint32_t *buf, int size, int ofs) { int ret; + uint32_t val_le; =20 trace_qemu_vfio_pci_read_config(buf, ofs, size, s->config_region_info.offset, s->config_region_info.size); assert(QEMU_IS_ALIGNED(s->config_region_info.offset + ofs, size)); ret =3D RETRY_ON_EINTR( - pread(s->device, buf, size, s->config_region_info.offset + ofs) + pread(s->device, &val_le, size, s->config_region_info.offset + ofs) ); + + *buf =3D le32_to_cpu(val_le); return ret =3D=3D size ? 0 : -errno; } =20 -static int qemu_vfio_pci_write_config(QEMUVFIOState *s, void *buf, int siz= e, int ofs) +static int qemu_vfio_pci_write_config(QEMUVFIOState *s, uint32_t *buf, int= size, int ofs) { int ret; + uint32_t val_le; =20 + val_le =3D cpu_to_le32(*buf); trace_qemu_vfio_pci_write_config(buf, ofs, size, s->config_region_info.offset, s->config_region_info.size); assert(QEMU_IS_ALIGNED(s->config_region_info.offset + ofs, size)); ret =3D RETRY_ON_EINTR( - pwrite(s->device, buf, size, s->config_region_info.offset + ofs) + pwrite(s->device, &val_le, size, s->config_region_info.offset + of= s) ); return ret =3D=3D size ? 0 : -errno; } @@ -296,7 +301,7 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const c= har *device, { int ret; int i; - uint16_t pci_cmd; + uint32_t pci_cmd; struct vfio_group_status group_status =3D { .argsz =3D sizeof(group_st= atus) }; struct vfio_iommu_type1_info *iommu_info =3D NULL; size_t iommu_info_size =3D sizeof(*iommu_info); --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297347; cv=none; d=zohomail.com; s=zohoarc; b=SjReAO7e8FcWdI4RdQdCW/IcqbD/ZQd8vWf1iS1n0LWROYrUacxb1FoQP2e2kqy4rkWcQbcuTAWvCSSDe28kZM/h2+RUpN+icoDRXgXNPpjZ/g/Y8vGzUb9H9n0Tj+MxE+9DDGkJRrSKtAa4i309uuSzcAOxGpZbq6NotdaG3IA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297347; 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=LuyLqPODn/+5yI6E9TiHYbIYAdhhhcmj4ZZnzoQ29NI=; b=QzFWvxf1/84XnDigYwWSQlpocXfYURcFquK7LXK+g1kukZL5qXXCqz9J+Cvcp33UVcvtlADx57djrI6nJIn+rO66ro4MCwxU8AutNa5xh+Qt2yPIMXUGEv3JFICvzbgDG9idBgDSGsOVe5hcwtf1c9GXfWzORQ3njJEC18sdbls= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297347189480.9919913705014; Tue, 13 Jan 2026 01:42:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfarX-0004BR-1Y; Tue, 13 Jan 2026 04:38:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar8-0003ZL-Oi for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar6-0003VN-JY for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:29 -0500 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-216-Ul4lVOsENaCCJ28X70cVZQ-1; Tue, 13 Jan 2026 04:38:24 -0500 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 A6005195605A; Tue, 13 Jan 2026 09:38:23 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B368530001A2; Tue, 13 Jan 2026 09:38:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297108; 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=LuyLqPODn/+5yI6E9TiHYbIYAdhhhcmj4ZZnzoQ29NI=; b=aF+y/b0/7JK6+eDfpxg7v0PKaGJqIhoO1XqIfk0JOsnVoCOeNB95tmSzXFw49r6eG9gjzK uGfQZb3ASxFe4QXM3Jv/jMRWM5if4rkcK0OWmXRTEr878KeDGiZEm47ObxwL4n7BWIRa2m iN5KI6S7Y20kWavYm3pYuC4Q2H4a3tA= X-MC-Unique: Ul4lVOsENaCCJ28X70cVZQ-1 X-Mimecast-MFC-AGG-ID: Ul4lVOsENaCCJ28X70cVZQ_1768297103 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Magnus Kulke Subject: [PULL 36/41] include/hw/hyperv: Remove unused 'struct mshv_vp_registers' definition Date: Tue, 13 Jan 2026 10:36:32 +0100 Message-ID: <20260113093637.1549214-37-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297348573158500 The 'struct mshv_vp_registers' definition in hvgdk_mini.h is unused in QEMU and conflicts with the canonical definition in linux-headers/linux/mshv.h. Remove the duplicate definition to avoid build conflicts when the Linux headers are updated. Cc: Magnus Kulke Reviewed-by: Magnus Kulke Link: https://lore.kernel.org/qemu-devel/20260108185012.2568277-1-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/hyperv/hvgdk_mini.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/include/hw/hyperv/hvgdk_mini.h b/include/hw/hyperv/hvgdk_mini.h index d89315f5452fd565469bbfc98cacb226b71da13f..cb52cc9de283bbe4201357127c2= eb1b0b37e4cab 100644 --- a/include/hw/hyperv/hvgdk_mini.h +++ b/include/hw/hyperv/hvgdk_mini.h @@ -450,13 +450,6 @@ typedef struct hv_input_set_vp_registers { struct hv_register_assoc elements[]; } hv_input_set_vp_registers; =20 -#define MSHV_VP_MAX_REGISTERS 128 - -struct mshv_vp_registers { - int count; /* at most MSHV_VP_MAX_REGISTERS */ - struct hv_register_assoc *regs; -}; - union hv_interrupt_control { uint64_t as_uint64; struct { --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297347; cv=none; d=zohomail.com; s=zohoarc; b=GhymcDlMm9snXxSrSYv4blp6aqpVOAfPV3FjLokxfBCW+fUDoPTv3HuVeNl2QLgWHQhpnzCLwwlNtazYqdSJfCbjyGoiTb/pwkHOoFzw+XKdufH/pJZDVKcphXi4bcf14Bx/Jt2yMh0m7BdHqmg6GDXAXx3F/kMeDm8sk+l31TE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297347; 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=yy63ZHiN12yeuydauCwj7xeOfVPviSR/0iTV9Z6fqtc=; b=lJVS3V9geMTk7ozsRykcxRfDVujF9IzK1+gFHuCjmtRLaeY+o+vplPVp2n/Bi5jU687c6ic3vFruS/+xLCKNnFT5f7KnnOgPqRo3Z6XJe6xT6bUB1xzLGi/D86WFV6RCJqFMphj6vD9ZyIHIEx76PoF+/+zmDIGZUafsc9K8q9s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297347604581.8741601929605; Tue, 13 Jan 2026 01:42:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfarX-0004M5-Nq; Tue, 13 Jan 2026 04:38:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar8-0003ZM-P0 for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar6-0003VR-UD for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:30 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-eXSAuk0XOsWxzY-sSdKZkw-1; Tue, 13 Jan 2026 04:38:27 -0500 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 15EC718005AF; Tue, 13 Jan 2026 09:38:26 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1759030001A8; Tue, 13 Jan 2026 09:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297108; 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=yy63ZHiN12yeuydauCwj7xeOfVPviSR/0iTV9Z6fqtc=; b=ELmZlIVHRVS8ECZQjkFMaR5H0O594p+/dwPLxGrzof/Hsr+dOnaJWOViEhmqufccUfq+8P pjSlmCq3N/nUZbLCokMozKuXesbDX1zcSMBfOXtrOw301jvCdrET4dYSC2NOABrhq8JSy1 ZicWq4oxY32DS2wh/gd+tVuAYjQMxM4= X-MC-Unique: eXSAuk0XOsWxzY-sSdKZkw-1 X-Mimecast-MFC-AGG-ID: eXSAuk0XOsWxzY-sSdKZkw_1768297106 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Shameer Kolothum , Thomas Huth , Cornelia Huck Subject: [PULL 37/41] update-linux-headers: Remove "asm-s390/unistd_32.h" Date: Tue, 13 Jan 2026 10:36:33 +0100 Message-ID: <20260113093637.1549214-38-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297348591158500 The "asm/unistd_32.h" file was generated for the 31-bit compatibility mode on the s390 architecture and support was removed in v6.19-rc1, commit 4ac286c4a8d9 ("s390/syscalls: Switch to generic system call table generation") unistd_32.h is no longer generated when running make header_install. Remove it. Reported-by: Shameer Kolothum Cc: Thomas Huth Reviewed-by: Thomas Huth Reviewed-by: Cornelia Huck Link: https://lore.kernel.org/qemu-devel/20260112155341.1209988-1-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- scripts/update-linux-headers.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers= .sh index 844d9cb9f5e430dcb4833e6225b57173f4befb8c..d09d8cf4c6f0f6a109e899f5c86= 71f64373d9c6a 100755 --- a/scripts/update-linux-headers.sh +++ b/scripts/update-linux-headers.sh @@ -154,7 +154,6 @@ EOF mkdir -p "$output/include/standard-headers/asm-$arch" if [ $arch =3D s390 ]; then cp_portable "$hdrdir/include/asm/virtio-ccw.h" "$output/include/st= andard-headers/asm-s390/" - cp "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-s3= 90/" cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-s3= 90/" fi if [ $arch =3D arm64 ]; then --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297209; cv=none; d=zohomail.com; s=zohoarc; b=Nc9aqKArMS2qTzf2ksVFXidiObmwhvjTlp/Tpem5VdtHQEMRqbXlGJ/ctYTlyzX9+LmSC4PFMvgooKYWzc3YxfdFIdqVNWZSZo049mCFcmSG6ghN4BDoktVC1qtQV5kjGjvY2t9/XxcSomb54hTthuJs7KedOR1c0nRf5CJv0zI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297209; 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=0RmdIUfs/XHrxEAnaB/sMmQy5fqjrWnUlwm356RtNpk=; b=S6mAjYlayntmtCutHokAguMjJcoU5d/0PsfX97sVa7qkdAmh8kIoeqrrLiDL+g6TZxwgXZ7/BcSrftmdWEZLRID9VOHC4KzBtAqUypK8R/h0mZJ1w+6T7p6Bbe030jTOGPQWuPDEM51ir8FNA61WJCvSUukJan/mIvyknYVpaSY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297209340195.33810596814726; Tue, 13 Jan 2026 01:40:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfarY-0004PH-Jl; Tue, 13 Jan 2026 04:38:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfarB-0003lU-IG for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfar9-0003Vz-Ud for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:33 -0500 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-682-VBPrcENdMyqXy-whEFht0Q-1; Tue, 13 Jan 2026 04:38:29 -0500 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 9CD6019560B2; Tue, 13 Jan 2026 09:38:28 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8761E30001A2; Tue, 13 Jan 2026 09:38:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297111; 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=0RmdIUfs/XHrxEAnaB/sMmQy5fqjrWnUlwm356RtNpk=; b=VaaHsz2t5SNGkWz+/6RUXrkD6EQ4UF8IbQqcipdG+SC9iHppIcNztx/XqoSpO4AT4PzG9T OHXqt5UJaE5Htc4Id0bP6ud7fLDy7vY+M0iLD/r6K/yb68TlIHR6OEnMxHnYiV+Ruhm/80 rejdU9JKiFvLZrUeYqxtoVcJs8v3QcA= X-MC-Unique: VBPrcENdMyqXy-whEFht0Q-1 X-Mimecast-MFC-AGG-ID: VBPrcENdMyqXy-whEFht0Q_1768297108 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alexey Kardashevskiy , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 38/41] ppc/vof: Fix build error Date: Tue, 13 Jan 2026 10:36:34 +0100 Message-ID: <20260113093637.1549214-39-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297210227158500 Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC)) detects an unused variable error: ../hw/ppc/vof.c: In function =E2=80=98vof_dt_memory_available=E2=80=99: ../hw/ppc/vof.c:642:12: error: variable =E2=80=98n=E2=80=99 set but not use= d [-Werror=3Dunused-but-set-variable=3D] Remove 'n'. Cc: Alexey Kardashevskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260112124722.1029212-1-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- hw/ppc/vof.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/ppc/vof.c b/hw/ppc/vof.c index 5ecfc6891047eb63f498fe286d57f52a54c0a0db..fa7b73159a0b476dfc49326139d= 75cb87ca487c1 100644 --- a/hw/ppc/vof.c +++ b/hw/ppc/vof.c @@ -639,7 +639,7 @@ static gint of_claimed_compare_func(gconstpointer a, gc= onstpointer b) =20 static void vof_dt_memory_available(void *fdt, GArray *claimed, uint64_t b= ase) { - int i, n, offset, proplen =3D 0, sc, ac; + int i, offset, proplen =3D 0, sc, ac; target_ulong mem0_end; const uint8_t *mem0_reg; g_autofree uint8_t *avail =3D NULL; @@ -677,7 +677,7 @@ static void vof_dt_memory_available(void *fdt, GArray *= claimed, uint64_t base) g_assert(claimed->len && (g_array_index(claimed, OfClaimed, 0).start = =3D=3D 0)); =20 avail =3D g_malloc0(sizeof(uint32_t) * (ac + sc) * claimed->len); - for (i =3D 0, n =3D 0, availcur =3D avail; i < claimed->len; ++i) { + for (i =3D 0, availcur =3D avail; i < claimed->len; ++i) { OfClaimed c =3D g_array_index(claimed, OfClaimed, i); uint64_t start, size; =20 @@ -705,7 +705,6 @@ static void vof_dt_memory_available(void *fdt, GArray *= claimed, uint64_t base) =20 if (size) { trace_vof_avail(c.start + c.size, c.start + c.size + size, siz= e); - ++n; } } _FDT((fdt_setprop(fdt, offset, "available", avail, availcur - avail))); --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297230; cv=none; d=zohomail.com; s=zohoarc; b=MSk/foU+6aZGKH5e37/TAQoqnbiX0Hk6we7nuom41LkxUA1uM1lStatm5RlwkgOnCf9/T//yAKBxrBP0oLVKQVWeX72Jb8l4BH93NNCyMMyxPCvRioASdiDNU0uT3hx/VU1kBrviNiqJzJYueN6/GuCUo36M5ff2023s73tVIXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297230; 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=0UFal5/EXhCIGHOGQKLaPbaoeQMeb4mww9g+nD++e4Q=; b=OkNMb1SlYehKS1spUMqB9N2D6nu7EbnwAKcnJ1loyjdDDHDT6xPL4qUFlPLL8zHGZawBzoMsxgb9kIQ8WP3Ydf59gMChAtRE+BsvAUW8A3JK7ogVYaF/mjNyxtX9COfDe7MWdx6G6MLw5yr8BCjucPgzpDhLnYeBAxs2y7wgwkk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297230692440.12846919501374; Tue, 13 Jan 2026 01:40:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfarZ-0004ea-Is; Tue, 13 Jan 2026 04:38:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfarI-0003sG-VW for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfarH-0003Wa-GB for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:40 -0500 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-196-V1OVL4S8ON-COHy-pZgJHA-1; Tue, 13 Jan 2026 04:38:33 -0500 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 12B8719560B5; Tue, 13 Jan 2026 09:38:32 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1A21B30001A2; Tue, 13 Jan 2026 09:38:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297119; 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=0UFal5/EXhCIGHOGQKLaPbaoeQMeb4mww9g+nD++e4Q=; b=Vn+5Y0V4XcoNi535L8yKVqSD8UBb+Jkyn5azIfZ7K3/+ExdQF8Ak+UueTzDmksXEXzLH21 G4V1zaQMiuxptiqJ86kMzTJPmk8gvNypqCj3Wod+G97mBmhxgy/dUJXcLf4wfaouQJlfin 3qm/0LWFNQY8j750wHuAJuRlVgbolc0= X-MC-Unique: V1OVL4S8ON-COHy-pZgJHA-1 X-Mimecast-MFC-AGG-ID: V1OVL4S8ON-COHy-pZgJHA_1768297112 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Daniel Henrique Barboza Subject: [PULL 39/41] target/riscv: Fix build errors Date: Tue, 13 Jan 2026 10:36:35 +0100 Message-ID: <20260113093637.1549214-40-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297232118158500 Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC)) detects a truncation error: ../target/riscv/cpu.c: In function =E2=80=98riscv_isa_write_fdt=E2=80=99: ../target/riscv/cpu.c:2916:35: error: =E2=80=98%d=E2=80=99 directive outp= ut may be truncated writing between 1 and 11 bytes into a region of size 5 = [-Werror=3Dformat-truncation=3D] 2916 | snprintf(isa_base, maxlen, "rv%di", xlen); | ^~ ../target/riscv/cpu.c:2916:32: note: directive argument in the range [-21= 47483648, 2147483632] 2916 | snprintf(isa_base, maxlen, "rv%di", xlen); | ^~~~~~~ Since the xlen variable represents the register width (32, 64, 128) in the RISC-V base ISA name, mask its value with a 8-bit bitmask to satisfy the size constraints on the snprintf output. Cc: Palmer Dabbelt Cc: Alistair Francis Cc: Weiwei Li Cc: Daniel Henrique Barboza Cc: Liu Zhiwei Reviewed-by: Daniel Henrique Barboza Link: https://lore.kernel.org/qemu-devel/20260112161626.1232639-1-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index ffd98e8eed468645b8ceb8a7adb45718bdc4444d..e95eea024939d2cbb5747781c29= 1fed0e1b07bb9 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -2913,7 +2913,7 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, ch= ar *nodename) riscv_isa =3D riscv_isa_string(cpu); qemu_fdt_setprop_string(fdt, nodename, "riscv,isa", riscv_isa); =20 - snprintf(isa_base, maxlen, "rv%di", xlen); + snprintf(isa_base, maxlen, "rv%di", xlen & 0xFF); qemu_fdt_setprop_string(fdt, nodename, "riscv,isa-base", isa_base); =20 isa_extensions =3D riscv_isa_extensions_list(cpu, &count); --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297197; cv=none; d=zohomail.com; s=zohoarc; b=RAD9oWQT0oOOgnnYwIJsWgXuc9hkqHMcFPws0cF0KpkZ76GaD7aC84+WbjQeeCsUoJn5cfyeJg7uovBIUKiTI5BDZT6421eVjPtgLAYiLVU4NFQ1r75N5Lv+IPpO7TCeVI2KRc45nYSKmjN0FUzJax/ZyRwEcmVgdlLlz1MOpJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297197; 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=k4KkBf5r7PCQVPgFWgcfd/49FOswq0SRVJv4jAyGOLg=; b=ZkdRyTrsJA2r1vQ6W+61BXR5AN7tLRNYdjGtBrynse4bDX6UTc6b4blMAPJ9SUHQWRrtFRv+E4SSYkC617kU9n76bknvn/pmL/Zi2jYts9aP6IfnqE2NsrpXJOmHQDIVvLfneT5tICt00KYqbMU75HftgUZ6MYO1s4K299fAkNc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297197443623.1931574016016; Tue, 13 Jan 2026 01:39:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfara-0004kF-D6; Tue, 13 Jan 2026 04:38:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfarH-0003rJ-36 for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfarF-0003WL-I7 for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:38 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-rEpS1RVOPrqOCq9HBvSHeQ-1; Tue, 13 Jan 2026 04:38:35 -0500 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 79837180057E; Tue, 13 Jan 2026 09:38:34 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 839D330001A2; Tue, 13 Jan 2026 09:38:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297116; 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=k4KkBf5r7PCQVPgFWgcfd/49FOswq0SRVJv4jAyGOLg=; b=hxcCzq4An7z6EpwiNHG4uy8Xigx2as5vnz6SxRyu5fjXD+/BPHU9j18enLJvsi/qj0F7S9 paJrcbiHYbbORHom6IbLclO9vk08Rxuqp0xImcX0YmN0D+ISHS3sAlzy44MppTyN4XejN7 Ocabrf5ABmy6+nSUwNxuewP+5zjlJio= X-MC-Unique: rEpS1RVOPrqOCq9HBvSHeQ-1 X-Mimecast-MFC-AGG-ID: rEpS1RVOPrqOCq9HBvSHeQ_1768297114 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Fabiano Rosas , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 40/41] tests/qtest: Fix build error Date: Tue, 13 Jan 2026 10:36:36 +0100 Message-ID: <20260113093637.1549214-41-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297197894158500 Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC)) detects an unused variable error: ../tests/qtest/libqtest.c: In function =E2=80=98qtest_qom_has_concrete_ty= pe=E2=80=99: ../tests/qtest/libqtest.c:1044:9: error: variable =E2=80=98idx=E2=80=99 s= et but not used [-Werror=3Dunused-but-set-variable=3D] Remove idx. Cc: Fabiano Rosas Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260112123146.1010621-1-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- tests/qtest/libqtest.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 132aa5113753031f58acf11ab2d4111803eef7be..794d8700857754b8614720bfa5a= 2d597e73955c1 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -1042,7 +1042,6 @@ static bool qtest_qom_has_concrete_type(const char *p= arent_typename, QObject *qobj; QString *qstr; QDict *devinfo; - int idx; =20 if (!list) { QDict *resp; @@ -1067,7 +1066,7 @@ static bool qtest_qom_has_concrete_type(const char *p= arent_typename, } } =20 - for (p =3D qlist_first(list), idx =3D 0; p; p =3D qlist_next(p), idx++= ) { + for (p =3D qlist_first(list); p; p =3D qlist_next(p)) { devinfo =3D qobject_to(QDict, qlist_entry_obj(p)); g_assert(devinfo); =20 --=20 2.52.0 From nobody Mon Feb 9 10:49:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1768297320; cv=none; d=zohomail.com; s=zohoarc; b=AEWBLCtWq0MwsOWiDBGwEbrKtynIqYtY5dckmGT2LcmlBClTDnUtEDRYGoXRENXHb59PJ5E0wxFuUYFPBPeEnbKdunf5s/k2nF82Y8TghqSauL2ETMizMldKb1KwgabQAlQtG8CufGOyjsjAy1ulsdKo2pL9l1xETdc3WGVgA4k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768297320; 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=t/ez37UZl0VfCletKk7E961niqzrd4GVb5O7hezAtxI=; b=Y/tS+HPwkMs86GtfppQYn0Xhsq8TBv0IwBhJocybIKCogtRqhDJGsw7YKbZWTddSQQkGXaAoF+443BHIWBKgTfmsLngCv7+lHTJf1vDqc8w6jwemZ/kJimH2s+wvpJNejORES+tCJrHcHMZDpg5FEh1zb9kSo3zvlnzZV2YlNGU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768297320104307.2121729529199; Tue, 13 Jan 2026 01:42:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfara-0004oF-PU; Tue, 13 Jan 2026 04:38:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfarL-0003tk-Br for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfarJ-0003Wl-Pb for qemu-devel@nongnu.org; Tue, 13 Jan 2026 04:38:43 -0500 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-516-kQrMskMMOyK1C79PJ7igzw-1; Tue, 13 Jan 2026 04:38:37 -0500 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 9673C195423A; Tue, 13 Jan 2026 09:38:36 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E9F4C30001A2; Tue, 13 Jan 2026 09:38:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768297121; 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=t/ez37UZl0VfCletKk7E961niqzrd4GVb5O7hezAtxI=; b=S511ZyntR8r+a6daJZLuxSdzMk6h/z66RKjUWELFclsFEypT7IN4M8l9xV02yIv6JnoqZj dmVKvGVNxSM1dlG0V0KYrRect6EATFToTUsaidQ0x6+WdE8XWMphEOO3vNNl35+EtbBzd2 hEw+njx3Df8X21G739LImNXMxBb1Up4= X-MC-Unique: kQrMskMMOyK1C79PJ7igzw-1 X-Mimecast-MFC-AGG-ID: kQrMskMMOyK1C79PJ7igzw_1768297116 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Richard Henderson Subject: [PULL 41/41] tests/rcutorture: Fix build error Date: Tue, 13 Jan 2026 10:36:37 +0100 Message-ID: <20260113093637.1549214-42-clg@redhat.com> In-Reply-To: <20260113093637.1549214-1-clg@redhat.com> References: <20260113093637.1549214-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1768297320397158500 Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC)) detects an unused variable error: ../tests/unit/rcutorture.c: In function =E2=80=98rcu_read_stress_test=E2= =80=99: ../tests/unit/rcutorture.c:251:18: error: variable =E2=80=98garbage=E2=80= =99 set but not used [-Werror=3Dunused-but-set-variable=3D] 251 | volatile int garbage =3D 0; | ^~~~~~~ Since the 'garbage' variable is used to generate memory reads from the CPU while holding the RCU lock, it can not be removed. Tag it as ((unused)) instead to silence the compiler warnings/errors. Reviewed-by: Richard Henderson Link: https://lore.kernel.org/qemu-devel/20260112163350.1251114-1-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- tests/unit/rcutorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/rcutorture.c b/tests/unit/rcutorture.c index 7662081683f5d781da74402113b73884780b1243..2f19d479a3f210cbca19205a065= 6eda1f4c2e5a7 100644 --- a/tests/unit/rcutorture.c +++ b/tests/unit/rcutorture.c @@ -248,7 +248,7 @@ static void *rcu_read_stress_test(void *arg) int pc; long long n_reads_local =3D 0; long long rcu_stress_local[RCU_STRESS_PIPE_LEN + 1] =3D { 0 }; - volatile int garbage =3D 0; + volatile int garbage __attribute__ ((unused)) =3D 0; =20 rcu_register_thread(); =20 --=20 2.52.0