From nobody Sat May 30 20:11:35 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=1776789352; cv=none; d=zohomail.com; s=zohoarc; b=FndbWyIsbQ7iJViOxALK1lT98ceydcnMdDvtXYmPNMISRHZO4dYtd3m/pPLxeR4PYZxroa3DWsC9ypJkWbgnPXRvlMjhN+TdypR7TD5x6ucBqiO3BTF1DVlb5HlVZirqv2hsr3CSHTsSnkLatLKzHJLNYjI5O2KLjItSMxD2Tc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789352; 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=/kYB8vK3HXzfENIO6q5Lq5Tn7QDuCndeJbYpyXiIukk=; b=HmtaSVloahbO84SFkYcFfRrXHrBxcQit10/GiJLdvpAaQiUUDyDRYeA6i4AZfxwA2G9Tgpwp6bgTBYHW4ZDyrWmMUSNB8+BnvrUU+V4fsnqikTcm6R3cyox6BuIMnz37o+wQchjv8BYzXo0vHaFDnXHWjM5BKloxaeW6lNUNPQY= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789352240131.36010441950305; Tue, 21 Apr 2026 09:35:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE4S-0004mN-P7; Tue, 21 Apr 2026 12:35:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE3t-0004Zm-Rw for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:34:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE3q-0007KB-Bk for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:34:56 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-519--IVaB97-PWKt81x4tLxPOw-1; Tue, 21 Apr 2026 12:34:45 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2BDE91956080; Tue, 21 Apr 2026 16:34:44 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5F0FB19560AB; Tue, 21 Apr 2026 16:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789289; 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=/kYB8vK3HXzfENIO6q5Lq5Tn7QDuCndeJbYpyXiIukk=; b=gqaoEUhrjxmVa5lHYx74iHZX75ug3vcK4icwYJvUbzv/tPbHBGmbqvvJJcr+R2neBF2Kep yYbHthUp9yepUX1zoCwk9Mu6NNK9lo4VJZ0j8I20UYUEnmP9cxabW+eX9AM+wqefLGop1X yNz7ycIvBSGZC7gaTYq/q3k/MBvMXqw= X-MC-Unique: -IVaB97-PWKt81x4tLxPOw-1 X-Mimecast-MFC-AGG-ID: -IVaB97-PWKt81x4tLxPOw_1776789284 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Pierrick Bouvier , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 01/14] hw/vfio/listener.c: remove CONFIG_KVM Date: Tue, 21 Apr 2026 18:34:25 +0200 Message-ID: <20260421163438.3447280-2-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1776789354615158500 From: Pierrick Bouvier Code concerned is under a kvm_enabled() guard. Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier Tested-by: C=C3=A9dric Le Goater Tested-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260318174733.1717643-2-pierrick.= bouvier@linaro.org Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/listener.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 960da9e0a9341e8123baed7839a32bc3f3acca57..31c3113f8fbe305081ffdd16cb2= 8cf8379926971 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -20,9 +20,7 @@ =20 #include "qemu/osdep.h" #include -#ifdef CONFIG_KVM #include -#endif #include =20 #include "exec/target_page.h" @@ -303,11 +301,9 @@ static bool vfio_ram_discard_register_listener(VFIOCon= tainer *bcontainer, if (bcontainer->dma_max_mappings) { unsigned int vrdl_count =3D 0, vrdl_mappings =3D 0, max_memslots = =3D 512; =20 -#ifdef CONFIG_KVM if (kvm_enabled()) { max_memslots =3D kvm_get_max_memslots(); } -#endif =20 QLIST_FOREACH(vrdl, &bcontainer->vrdl_list, next) { hwaddr start, end; --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789481; cv=none; d=zohomail.com; s=zohoarc; b=Th4QR2cXYrNSqqqfOPiN4/1O2rhTClPPqY1SJlDe8Rr0oPIx9YkEmGbYJm01Euhj/2M1hJ0ME8xvPZ9ncDMdngWfd4k3rK6hKyqvvFooyi4HifhBRA3/kktqFXwtrW/RbQDWlFItfkhwY30oPFigwcWpG5/AxUWB4OUvWDxxaZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789481; 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=gZWM2kQuZy+59YJLKvLBs1e6rIWb4i3/E9198uvLvD8=; b=X757EXPzYYLCECrYqVZvOg2YRgRDrBxXJq98ib2GUpGjq0ApDlSO+bxbAiTlaWnKgP+Nds3YuK/8bvN/RiOEdBcYxK++nzldeM/1BcPH6Xgpou1uTD9oq8NhS+YPlqxi6c/qjZ3aIU7J1Cnd4NobdGr5XHDLLcK1b/n2+0724Ag= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789481712337.4877701385011; Tue, 21 Apr 2026 09:38:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE4x-0004sw-Rq; Tue, 21 Apr 2026 12:36:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE40-0004aG-OM for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE3q-0007KT-Cc for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:34:58 -0400 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-473-86wLxg-MNCC-FDZkFmCEaw-1; Tue, 21 Apr 2026 12:34:47 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AD9D21800464; Tue, 21 Apr 2026 16:34:46 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9A61B1956095; Tue, 21 Apr 2026 16:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789293; 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=gZWM2kQuZy+59YJLKvLBs1e6rIWb4i3/E9198uvLvD8=; b=aQQBaBSOweyTE5ICGaC61E2inXtFkjqq+p0PmcRTLXfhE26SPhsevPy8w3NWKf8e/esMf3 zwgCiGHRWdDQ9R87PWp58+Otr3uO+a7p28084prnpcFztUfwwe7kqO5kwgc1Y+yOchmHxb QRTwK6i14Cx6/tCUO4Vs/3pqvBGx3KY= X-MC-Unique: 86wLxg-MNCC-FDZkFmCEaw-1 X-Mimecast-MFC-AGG-ID: 86wLxg-MNCC-FDZkFmCEaw_1776789286 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Pierrick Bouvier , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 02/14] hw/vfio/helpers.c: extract kvm helpers in kvm-helpers.c Date: Tue, 21 Apr 2026 18:34:26 +0200 Message-ID: <20260421163438.3447280-3-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1776789484542154100 From: Pierrick Bouvier Because those functions use kvm specific types, they need to be isolated in another source file. This allows us to link kvm-helpers only in configurations with CONFIG_KVM. Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier Tested-by: C=C3=A9dric Le Goater Tested-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260318174733.1717643-3-pierrick.= bouvier@linaro.org Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/helpers.c | 172 ------------------------------------- hw/vfio/kvm-helpers.c | 192 ++++++++++++++++++++++++++++++++++++++++++ hw/vfio/kvm-stubs.c | 26 ++++++ hw/vfio/meson.build | 2 + 4 files changed, 220 insertions(+), 172 deletions(-) create mode 100644 hw/vfio/kvm-helpers.c create mode 100644 hw/vfio/kvm-stubs.c diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 00d42d3b98ef98368bb30ff11098615c881cf0a8..65c6dba0428954170ce8a889edf= fa34ce9b24b13 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -22,7 +22,6 @@ #include "qemu/osdep.h" #include =20 -#include "system/kvm.h" #include "exec/cpu-common.h" #include "hw/vfio/vfio-device.h" #include "hw/core/hw-error.h" @@ -107,177 +106,6 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_= info *info, return true; } =20 -#ifdef CONFIG_KVM -/* - * We have a single VFIO pseudo device per KVM VM. Once created it lives - * for the life of the VM. Closing the file descriptor only drops our - * reference to it and the device's reference to kvm. Therefore once - * initialized, this file descriptor is only released on QEMU exit and - * we'll re-use it should another vfio device be attached before then. - */ -int vfio_kvm_device_fd =3D -1; - -/* - * Confidential virtual machines: - * During reset of confidential vms, the kvm vm file descriptor changes. - * In this case, the old vfio kvm file descriptor is - * closed and a new descriptor is created against the new kvm vm file - * descriptor. - */ - -typedef struct VFIODeviceFd { - int fd; - QLIST_ENTRY(VFIODeviceFd) node; -} VFIODeviceFd; - -static QLIST_HEAD(, VFIODeviceFd) vfio_device_fds =3D - QLIST_HEAD_INITIALIZER(vfio_device_fds); - -static void vfio_device_fd_list_add(int fd) -{ - VFIODeviceFd *file_fd; - file_fd =3D g_malloc0(sizeof(*file_fd)); - file_fd->fd =3D fd; - QLIST_INSERT_HEAD(&vfio_device_fds, file_fd, node); -} - -static void vfio_device_fd_list_remove(int fd) -{ - VFIODeviceFd *file_fd, *next; - - QLIST_FOREACH_SAFE(file_fd, &vfio_device_fds, node, next) { - if (file_fd->fd =3D=3D fd) { - QLIST_REMOVE(file_fd, node); - g_free(file_fd); - break; - } - } -} - -static int vfio_device_fd_rebind(NotifierWithReturn *notifier, void *data, - Error **errp) -{ - VFIODeviceFd *file_fd; - struct kvm_device_attr attr =3D { - .group =3D KVM_DEV_VFIO_FILE, - .attr =3D KVM_DEV_VFIO_FILE_ADD, - }; - struct kvm_create_device cd =3D { - .type =3D KVM_DEV_TYPE_VFIO, - }; - - /* we are not interested in pre vmfd change notification */ - if (((VmfdChangeNotifier *)data)->pre) { - return 0; - } - - if (kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd)) { - error_setg_errno(errp, errno, "Failed to create KVM VFIO device"); - return -errno; - } - - if (vfio_kvm_device_fd !=3D -1) { - close(vfio_kvm_device_fd); - } - - vfio_kvm_device_fd =3D cd.fd; - - QLIST_FOREACH(file_fd, &vfio_device_fds, node) { - attr.addr =3D (uint64_t)(unsigned long)&file_fd->fd; - if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { - error_setg_errno(errp, errno, - "Failed to add fd %d to KVM VFIO device", - file_fd->fd); - return -errno; - } - } - return 0; -} - -static struct NotifierWithReturn vfio_vmfd_change_notifier =3D { - .notify =3D vfio_device_fd_rebind, -}; - -#endif - -void vfio_kvm_device_close(void) -{ -#ifdef CONFIG_KVM - kvm_close(); - if (vfio_kvm_device_fd !=3D -1) { - close(vfio_kvm_device_fd); - vfio_kvm_device_fd =3D -1; - } -#endif -} - -int vfio_kvm_device_add_fd(int fd, Error **errp) -{ -#ifdef CONFIG_KVM - struct kvm_device_attr attr =3D { - .group =3D KVM_DEV_VFIO_FILE, - .attr =3D KVM_DEV_VFIO_FILE_ADD, - .addr =3D (uint64_t)(unsigned long)&fd, - }; - - if (!kvm_enabled()) { - return 0; - } - - if (vfio_kvm_device_fd < 0) { - struct kvm_create_device cd =3D { - .type =3D KVM_DEV_TYPE_VFIO, - }; - - if (kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd)) { - error_setg_errno(errp, errno, "Failed to create KVM VFIO devic= e"); - return -errno; - } - - vfio_kvm_device_fd =3D cd.fd; - /* - * If the vm file descriptor changes, add a notifier so that we can - * re-create the vfio_kvm_device_fd. - */ - kvm_vmfd_add_change_notifier(&vfio_vmfd_change_notifier); - } - - if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { - error_setg_errno(errp, errno, "Failed to add fd %d to KVM VFIO dev= ice", - fd); - return -errno; - } - - vfio_device_fd_list_add(fd); -#endif - return 0; -} - -int vfio_kvm_device_del_fd(int fd, Error **errp) -{ -#ifdef CONFIG_KVM - struct kvm_device_attr attr =3D { - .group =3D KVM_DEV_VFIO_FILE, - .attr =3D KVM_DEV_VFIO_FILE_DEL, - .addr =3D (uint64_t)(unsigned long)&fd, - }; - - if (vfio_kvm_device_fd < 0) { - error_setg(errp, "KVM VFIO device isn't created yet"); - return -EINVAL; - } - - if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { - error_setg_errno(errp, errno, - "Failed to remove fd %d from KVM VFIO device", fd= ); - return -errno; - } - - vfio_device_fd_list_remove(fd); -#endif - return 0; -} - struct vfio_device_info *vfio_get_device_info(int fd) { struct vfio_device_info *info; diff --git a/hw/vfio/kvm-helpers.c b/hw/vfio/kvm-helpers.c new file mode 100644 index 0000000000000000000000000000000000000000..d71c9590aaa53dc4e436987a345= 75f57a6397c6b --- /dev/null +++ b/hw/vfio/kvm-helpers.c @@ -0,0 +1,192 @@ +/* + * low level and IOMMU backend agnostic helpers used by VFIO devices, + * related to regions, interrupts, capabilities + * + * Copyright Red Hat, Inc. 2012 + * + * Authors: + * Alex Williamson + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * Based on qemu-kvm device-assignment: + * Adapted for KVM by Qumranet. + * Copyright (c) 2007, Neocleus, Alex Novik (alex@neocleus.com) + * Copyright (c) 2007, Neocleus, Guy Zana (guy@neocleus.com) + * Copyright (C) 2008, Qumranet, Amit Shah (amit.shah@qumranet.com) + * Copyright (C) 2008, Red Hat, Amit Shah (amit.shah@redhat.com) + * Copyright (C) 2008, IBM, Muli Ben-Yehuda (muli@il.ibm.com) + */ + +#include "qemu/osdep.h" +#include + +#include +#include "system/kvm.h" +#include "exec/cpu-common.h" +#include "hw/vfio/vfio-device.h" +#include "hw/core/hw-error.h" +#include "qapi/error.h" +#include "vfio-helpers.h" + +/* + * We have a single VFIO pseudo device per KVM VM. Once created it lives + * for the life of the VM. Closing the file descriptor only drops our + * reference to it and the device's reference to kvm. Therefore once + * initialized, this file descriptor is only released on QEMU exit and + * we'll re-use it should another vfio device be attached before then. + */ +int vfio_kvm_device_fd =3D -1; + +/* + * Confidential virtual machines: + * During reset of confidential vms, the kvm vm file descriptor changes. + * In this case, the old vfio kvm file descriptor is + * closed and a new descriptor is created against the new kvm vm file + * descriptor. + */ + +typedef struct VFIODeviceFd { + int fd; + QLIST_ENTRY(VFIODeviceFd) node; +} VFIODeviceFd; + +static QLIST_HEAD(, VFIODeviceFd) vfio_device_fds =3D + QLIST_HEAD_INITIALIZER(vfio_device_fds); + +static void vfio_device_fd_list_add(int fd) +{ + VFIODeviceFd *file_fd; + file_fd =3D g_malloc0(sizeof(*file_fd)); + file_fd->fd =3D fd; + QLIST_INSERT_HEAD(&vfio_device_fds, file_fd, node); +} + +static void vfio_device_fd_list_remove(int fd) +{ + VFIODeviceFd *file_fd, *next; + + QLIST_FOREACH_SAFE(file_fd, &vfio_device_fds, node, next) { + if (file_fd->fd =3D=3D fd) { + QLIST_REMOVE(file_fd, node); + g_free(file_fd); + break; + } + } +} + +static int vfio_device_fd_rebind(NotifierWithReturn *notifier, void *data, + Error **errp) +{ + VFIODeviceFd *file_fd; + struct kvm_device_attr attr =3D { + .group =3D KVM_DEV_VFIO_FILE, + .attr =3D KVM_DEV_VFIO_FILE_ADD, + }; + struct kvm_create_device cd =3D { + .type =3D KVM_DEV_TYPE_VFIO, + }; + + /* we are not interested in pre vmfd change notification */ + if (((VmfdChangeNotifier *)data)->pre) { + return 0; + } + + if (kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd)) { + error_setg_errno(errp, errno, "Failed to create KVM VFIO device"); + return -errno; + } + + if (vfio_kvm_device_fd !=3D -1) { + close(vfio_kvm_device_fd); + } + + vfio_kvm_device_fd =3D cd.fd; + + QLIST_FOREACH(file_fd, &vfio_device_fds, node) { + attr.addr =3D (uint64_t)(unsigned long)&file_fd->fd; + if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { + error_setg_errno(errp, errno, + "Failed to add fd %d to KVM VFIO device", + file_fd->fd); + return -errno; + } + } + return 0; +} + +static struct NotifierWithReturn vfio_vmfd_change_notifier =3D { + .notify =3D vfio_device_fd_rebind, +}; + +void vfio_kvm_device_close(void) +{ + kvm_close(); + if (vfio_kvm_device_fd !=3D -1) { + close(vfio_kvm_device_fd); + vfio_kvm_device_fd =3D -1; + } +} + +int vfio_kvm_device_add_fd(int fd, Error **errp) +{ + struct kvm_device_attr attr =3D { + .group =3D KVM_DEV_VFIO_FILE, + .attr =3D KVM_DEV_VFIO_FILE_ADD, + .addr =3D (uint64_t)(unsigned long)&fd, + }; + + if (!kvm_enabled()) { + return 0; + } + + if (vfio_kvm_device_fd < 0) { + struct kvm_create_device cd =3D { + .type =3D KVM_DEV_TYPE_VFIO, + }; + + if (kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd)) { + error_setg_errno(errp, errno, "Failed to create KVM VFIO devic= e"); + return -errno; + } + + vfio_kvm_device_fd =3D cd.fd; + /* + * If the vm file descriptor changes, add a notifier so that we can + * re-create the vfio_kvm_device_fd. + */ + kvm_vmfd_add_change_notifier(&vfio_vmfd_change_notifier); + } + + if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { + error_setg_errno(errp, errno, "Failed to add fd %d to KVM VFIO dev= ice", + fd); + return -errno; + } + + vfio_device_fd_list_add(fd); + return 0; +} + +int vfio_kvm_device_del_fd(int fd, Error **errp) +{ + struct kvm_device_attr attr =3D { + .group =3D KVM_DEV_VFIO_FILE, + .attr =3D KVM_DEV_VFIO_FILE_DEL, + .addr =3D (uint64_t)(unsigned long)&fd, + }; + + if (vfio_kvm_device_fd < 0) { + error_setg(errp, "KVM VFIO device isn't created yet"); + return -EINVAL; + } + + if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { + error_setg_errno(errp, errno, + "Failed to remove fd %d from KVM VFIO device", fd= ); + return -errno; + } + + vfio_device_fd_list_remove(fd); + return 0; +} diff --git a/hw/vfio/kvm-stubs.c b/hw/vfio/kvm-stubs.c new file mode 100644 index 0000000000000000000000000000000000000000..5a489d1b7110a5564054398cc35= 4bb806ac39334 --- /dev/null +++ b/hw/vfio/kvm-stubs.c @@ -0,0 +1,26 @@ +/* + * Stubs for kvm helpers + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +#include "hw/vfio/vfio-device.h" +#include "qapi/error.h" +#include "vfio-helpers.h" + +void vfio_kvm_device_close(void) +{ + return; +} + +int vfio_kvm_device_add_fd(int fd, Error **errp) +{ + return 0; +} + +int vfio_kvm_device_del_fd(int fd, Error **errp) +{ + return 0; +} diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index 82f68698fb8483196d5ced096f79d1024bf9c4bc..f2a7728d3d00f70b6a6f6e3ea24= 749e6246b5c43 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -7,6 +7,8 @@ vfio_ss.add(files( 'container-legacy.c', 'helpers.c', )) +vfio_ss.add(when: 'CONFIG_KVM', if_true: files('kvm-helpers.c')) +stub_ss.add(files('kvm-stubs.c')) vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c')) vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( 'pci-quirks.c', --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789466; cv=none; d=zohomail.com; s=zohoarc; b=kzrMYBpS1YNZdBxDve63F733e613Oh1EHvyKzK8lz39gI2RQIQG1pAfDMg1RBqKVcguf+KOEp/b7xLPsdNFJd+VdOI0Dcx1Vfh9Pp5uQ/ooIlTvWzenTVQwQAqsmcdvkxIHD8avtgEqBGqG4/xC8UJmBH2sUdDdti6Bgk18aisA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789466; 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=8xxmDsZWnKddXny8XJXbH9vxYlCbZpDY9wqE6WUzTjA=; b=kOnCE34qkFNyluIPcmDFk3OZHsIvi93VONYX53YBzuEQYHz9/AZOUrSpTBvSAgNaPpjNoliMbiomDShDZdP2yB7Y0p78FE/68wFCCDV4yyAeRbaX6Ble3XYxSUbxleR+u0xXLXX++vMTeiBJ/7xMDtlOwAyhQPnbBeO32G9a8oo= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789466438789.6295459559323; Tue, 21 Apr 2026 09:37:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE55-0004xd-Oa; Tue, 21 Apr 2026 12:36:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE47-0004gr-FS for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE3t-0007NK-Mx for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:06 -0400 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-656-PIrh7glOMqiQvKw1fUIX0A-1; Tue, 21 Apr 2026 12:34:51 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0354C1800451; Tue, 21 Apr 2026 16:34:49 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2A52119560AB; Tue, 21 Apr 2026 16:34:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789296; 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=8xxmDsZWnKddXny8XJXbH9vxYlCbZpDY9wqE6WUzTjA=; b=Iwxo+whJWCRsQemcZW+fLtJBqn0fO7wpNHt9B2AkQ0tMsc8+YwllmtZ2bTLRlTfnBvPHcg VAuQ3Zp4w/3QsHWAspiV1W/Up+65hhTVNEFfahGkT2dPKlt7IknZDs/t55VhAE+jgYcvSt hfHx86hIPVn3PyWD7i4K4tS4eKPeXRQ= X-MC-Unique: PIrh7glOMqiQvKw1fUIX0A-1 X-Mimecast-MFC-AGG-ID: PIrh7glOMqiQvKw1fUIX0A_1776789289 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Pierrick Bouvier , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 03/14] hw/vfio/pci-quirks.c: remove CONFIG_VFIO_IGD Date: Tue, 21 Apr 2026 18:34:27 +0200 Message-ID: <20260421163438.3447280-4-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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, 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: 1776789468178154100 From: Pierrick Bouvier Add stubs for needed functions. vfio_pci_hot_reset_info must be forwarded declared on non linux platforms: In file included from ../hw/vfio/igd-stubs.c:9: ../hw/vfio/pci.h:265:44: error: 'struct vfio_pci_hot_reset_info' declared i= nside parameter list will not be visible outside of this definition or decl= aration [-Werror] 265 | struct vfio_pci_hot_reset_info = **info_p); | Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier Tested-by: C=C3=A9dric Le Goater Tested-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260318174733.1717643-4-pierrick.= bouvier@linaro.org Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 2 ++ hw/vfio/igd-stubs.c | 20 ++++++++++++++++++++ hw/vfio/pci-quirks.c | 5 ----- hw/vfio/meson.build | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 hw/vfio/igd-stubs.c diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index d6495d7f297513605db363dcdb3dd9b8dfb29a8d..c3a1f53d35004c914854c97d6e3= 608e4a20b121a 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -258,6 +258,8 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, E= rror **errp); =20 extern const PropertyInfo qdev_prop_nv_gpudirect_clique; =20 +struct vfio_pci_hot_reset_info; + void vfio_pci_pre_reset(VFIOPCIDevice *vdev); void vfio_pci_post_reset(VFIOPCIDevice *vdev); bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name); diff --git a/hw/vfio/igd-stubs.c b/hw/vfio/igd-stubs.c new file mode 100644 index 0000000000000000000000000000000000000000..f7687d909125c2233e76f7e6d03= aa90f38c3b89f --- /dev/null +++ b/hw/vfio/igd-stubs.c @@ -0,0 +1,20 @@ +/* + * IGD device quirks stubs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/qmp/qerror.h" +#include "pci.h" +#include "pci-quirks.h" + +void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) +{ + return; +} + +bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) +{ + return true; +} diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index 66e02b15a481aa810cca6fac465e64639673e970..bccf31751fd47387fd89110e27b= 695e5c822d5c4 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -11,7 +11,6 @@ */ =20 #include "qemu/osdep.h" -#include CONFIG_DEVICES #include "exec/memop.h" #include "qemu/units.h" #include "qemu/log.h" @@ -1128,11 +1127,9 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDev= ice *vdev, int nr) */ bool vfio_config_quirk_setup(VFIOPCIDevice *vdev, Error **errp) { -#ifdef CONFIG_VFIO_IGD if (!vfio_probe_igd_config_quirk(vdev, errp)) { return false; } -#endif return true; } =20 @@ -1179,9 +1176,7 @@ void vfio_bar_quirk_setup(VFIOPCIDevice *vdev, int nr) vfio_probe_nvidia_bar5_quirk(vdev, nr); vfio_probe_nvidia_bar0_quirk(vdev, nr); vfio_probe_rtl8168_bar2_quirk(vdev, nr); -#ifdef CONFIG_VFIO_IGD vfio_probe_igd_bar0_quirk(vdev, nr); -#endif } =20 void vfio_bar_quirk_exit(VFIOPCIDevice *vdev, int nr) diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index f2a7728d3d00f70b6a6f6e3ea24749e6246b5c43..6c00a7f51bbe79d8e45d828a11d= 4deecf21512be 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -17,6 +17,7 @@ vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c')) vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c')) vfio_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files('igd.c')) +stub_ss.add(files('igd-stubs.c')) =20 specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss) =20 --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789485; cv=none; d=zohomail.com; s=zohoarc; b=h5t+xGDICwWjGSOZuul248TqyqPlHQ6GtUFv14zIw34lRDTim3i3xZEjh6ohZ1Kg05njgdNsIxWHXYX9qzsthTlQ5wmUIDiUvgi/uypHAQMGQGd9Bw8+kD2vxPGrI+IJStfH2jMt9hcCNBG3z+MUv6zWPzhXP5Zi0OdB+U+yILA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789485; 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=2aZygv18QyrraI5duFZEhvUtiCLkK2qjW57P+380aKo=; b=CgxpUaAyPdEDvRBbrM4dNu/JEkoMNbV0UBXA+FkAeHRKyE270g+HLfmFbxhNeIV9MPaVSw66uM2VHUrg4lA8aYwiRxKmFQqp1QSan2xoOlShxCGeuOsxlK+jr8uTUD8li56IVdMPkvrqp8SvO3GfSlEcQzvAxVEZ5P1ZWQosM60= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789485402107.32987009746807; Tue, 21 Apr 2026 09:38:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE55-0004wf-DP; Tue, 21 Apr 2026 12:36:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE40-0004aH-OY for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE3s-0007Mq-M0 for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:34:58 -0400 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-572-GbRd4z22OHe5gd_rHo0WdA-1; Tue, 21 Apr 2026 12:34:52 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 524DB1800345; Tue, 21 Apr 2026 16:34:51 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 71F9A1956095; Tue, 21 Apr 2026 16:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789296; 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=2aZygv18QyrraI5duFZEhvUtiCLkK2qjW57P+380aKo=; b=AG5TuopoTuE4HxjjbmpCQwLgjEJVpuZqGtTOj7fs1ciu+1H0yTykPV4xI45SXpiMiFpJrD yFhq+0DPmYvygnVpubl41A6NhemivZOx+0Zr+spZeiwt4XLmj0Kq+KUIJFSlADEkL6hFpe M249d8zTLQJK2chP8jSgloniI/spZpQ= X-MC-Unique: GbRd4z22OHe5gd_rHo0WdA-1 X-Mimecast-MFC-AGG-ID: GbRd4z22OHe5gd_rHo0WdA_1776789291 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Pierrick Bouvier , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 04/14] hw/vfio: eradicate CONFIG_IOMMU from sources Date: Tue, 21 Apr 2026 18:34:28 +0200 Message-ID: <20260421163438.3447280-5-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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, 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: 1776789486560154100 From: Pierrick Bouvier This commit removes usage of CONFIG_IOMMU in hw/vfio sources, exposing inconditionally iommufd related properties, which are declared statically (in const arrays). The alternative to expose them dynamically is more complex and requires boilerplate to set properties at runtime, with set_* callbacks and added logic to check if iommufd backend is available, with no obvious benefit. One possible difference is that user may see a different error message when trying to attach a vfio device with a QEMU not supporting iommufd, without declaring iommufd object associated. Instead of: ``` $ qemu-system-* -device vfio-pci,host=3D0000:01:00.0,iommufd=3Diommufd0 qemu-system-*: -device vfio-pci,host=3D0000:01:00.0,iommufd=3Diommufd0: Pro= perty 'vfio-pci.iommufd' not found ``` User will now see: ``` qemu-system-aarch64: -device vfio-pci,host=3D0000:01:00.0,iommufd=3Diommufd= 0: Device 'iommufd0' not found ``` However, since declaring the iommufd object is needed, error reported before and after is still the same: ``` $ qemu-system-* -object iommufd,id=3Diommufd0 -device vfio-pci,host=3D0000:= 01:00.0,iommufd=3Diommufd0 qemu-system-*: invalid object type: iommufd ``` Signed-off-by: Pierrick Bouvier Reviewed-by: C=C3=A9dric Le Goater Tested-by: C=C3=A9dric Le Goater Tested-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260318174733.1717643-5-pierrick.= bouvier@linaro.org Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/ap.c | 9 --------- hw/vfio/ccw.c | 9 --------- hw/vfio/pci.c | 11 ----------- 3 files changed, 29 deletions(-) diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 5c8f3056530c7027670f042ac920bd9e4a3da6e9..be20d7e7dc67f21363863f8c6d8= b2a7cdedb8762 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -11,7 +11,6 @@ */ =20 #include "qemu/osdep.h" -#include CONFIG_DEVICES /* CONFIG_IOMMUFD */ #include #include #include "qapi/error.h" @@ -279,10 +278,8 @@ static void vfio_ap_unrealize(DeviceState *dev) =20 static const Property vfio_ap_properties[] =3D { DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev), -#ifdef CONFIG_IOMMUFD DEFINE_PROP_LINK("iommufd", VFIOAPDevice, vdev.iommufd, TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), -#endif }; =20 static void vfio_ap_reset(DeviceState *dev) @@ -320,21 +317,17 @@ static void vfio_ap_instance_init(Object *obj) vbasedev->mdev =3D true; } =20 -#ifdef CONFIG_IOMMUFD static void vfio_ap_set_fd(Object *obj, const char *str, Error **errp) { vfio_device_set_fd(&VFIO_AP_DEVICE(obj)->vdev, str, errp); } -#endif =20 static void vfio_ap_class_init(ObjectClass *klass, const void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 device_class_set_props(dc, vfio_ap_properties); -#ifdef CONFIG_IOMMUFD object_class_property_add_str(klass, "fd", NULL, vfio_ap_set_fd); -#endif dc->vmsd =3D &vfio_ap_vmstate; dc->desc =3D "VFIO-based AP device assignment"; set_bit(DEVICE_CATEGORY_MISC, dc->categories); @@ -347,11 +340,9 @@ static void vfio_ap_class_init(ObjectClass *klass, con= st void *data) object_class_property_set_description(klass, /* 3.1 */ "sysfsdev", "Host sysfs path of assigned dev= ice"); -#ifdef CONFIG_IOMMUFD object_class_property_set_description(klass, /* 9.0 */ "iommufd", "Set host IOMMUFD backend device= "); -#endif } =20 static const TypeInfo vfio_ap_info =3D { diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index ce9c014e6a7f23b2eceecc05bc60509ece270e4b..ff6ab9a7408f01b9e64ba06f2c8= da4a69fa1f9ff 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -15,7 +15,6 @@ */ =20 #include "qemu/osdep.h" -#include CONFIG_DEVICES /* CONFIG_IOMMUFD */ #include #include #include @@ -647,10 +646,8 @@ static void vfio_ccw_unrealize(DeviceState *dev) static const Property vfio_ccw_properties[] =3D { DEFINE_PROP_STRING("sysfsdev", VFIOCCWDevice, vdev.sysfsdev), DEFINE_PROP_BOOL("force-orb-pfch", VFIOCCWDevice, force_orb_pfch, fals= e), -#ifdef CONFIG_IOMMUFD DEFINE_PROP_LINK("iommufd", VFIOCCWDevice, vdev.iommufd, TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), -#endif DEFINE_PROP_CCW_LOADPARM("loadparm", CcwDevice, loadparm), }; =20 @@ -679,12 +676,10 @@ static void vfio_ccw_instance_init(Object *obj) DEVICE(vcdev), true); } =20 -#ifdef CONFIG_IOMMUFD static void vfio_ccw_set_fd(Object *obj, const char *str, Error **errp) { vfio_device_set_fd(&VFIO_CCW(obj)->vdev, str, errp); } -#endif =20 static void vfio_ccw_class_init(ObjectClass *klass, const void *data) { @@ -692,9 +687,7 @@ static void vfio_ccw_class_init(ObjectClass *klass, con= st void *data) S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_CLASS(klass); =20 device_class_set_props(dc, vfio_ccw_properties); -#ifdef CONFIG_IOMMUFD object_class_property_add_str(klass, "fd", NULL, vfio_ccw_set_fd); -#endif dc->vmsd =3D &vfio_ccw_vmstate; dc->desc =3D "VFIO-based subchannel assignment"; set_bit(DEVICE_CATEGORY_MISC, dc->categories); @@ -713,11 +706,9 @@ static void vfio_ccw_class_init(ObjectClass *klass, co= nst void *data) object_class_property_set_description(klass, /* 3.0 */ "force-orb-pfch", "Force unlimited prefetch"); -#ifdef CONFIG_IOMMUFD object_class_property_set_description(klass, /* 9.0 */ "iommufd", "Set host IOMMUFD backend device= "); -#endif object_class_property_set_description(klass, /* 9.2 */ "loadparm", "Define which devices that can b= e used for booting"); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 1945751ffd44dd129768ac7788f0375b216f1747..1f1f3aaad9a901a087ecad1b5c4= 6e8756b3a6339 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -19,7 +19,6 @@ */ =20 #include "qemu/osdep.h" -#include CONFIG_DEVICES /* CONFIG_IOMMUFD */ #include #include =20 @@ -3471,9 +3470,7 @@ static void vfio_pci_realize(PCIDevice *pdev, Error *= *errp) ~vdev->host.slot || ~vdev->host.function)) { error_setg(errp, "No provided host device"); error_append_hint(errp, "Use -device vfio-pci,host=3DDDDD:BB:D= D.F " -#ifdef CONFIG_IOMMUFD "or -device vfio-pci,fd=3DDEVICE_FD " -#endif "or -device vfio-pci,sysfsdev=3DPATH_TO_DEVI= CE\n"); return; } @@ -3816,22 +3813,18 @@ static const Property vfio_pci_properties[] =3D { qdev_prop_nv_gpudirect_clique, uint8_t), DEFINE_PROP_OFF_AUTO_PCIBAR("x-msix-relocation", VFIOPCIDevice, msix_r= elo, OFF_AUTO_PCIBAR_OFF), -#ifdef CONFIG_IOMMUFD DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd, TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), -#endif DEFINE_PROP_BOOL("skip-vsc-check", VFIOPCIDevice, skip_vsc_check, true= ), DEFINE_PROP_UINT16("x-vpasid-cap-offset", VFIOPCIDevice, vpasid_cap_offset, 0), }; =20 -#ifdef CONFIG_IOMMUFD static void vfio_pci_set_fd(Object *obj, const char *str, Error **errp) { VFIOPCIDevice *vdev =3D VFIO_PCI_DEVICE(obj); vfio_device_set_fd(&vdev->vbasedev, str, errp); } -#endif =20 static void vfio_pci_class_init(ObjectClass *klass, const void *data) { @@ -3840,9 +3833,7 @@ static void vfio_pci_class_init(ObjectClass *klass, c= onst void *data) =20 device_class_set_legacy_reset(dc, vfio_pci_reset); device_class_set_props(dc, vfio_pci_properties); -#ifdef CONFIG_IOMMUFD object_class_property_add_str(klass, "fd", NULL, vfio_pci_set_fd); -#endif dc->vmsd =3D &vfio_cpr_pci_vmstate; dc->desc =3D "VFIO-based PCI device assignment"; pdc->realize =3D vfio_pci_realize; @@ -3944,11 +3935,9 @@ static void vfio_pci_class_init(ObjectClass *klass, = const void *data) "vf-token", "Specify UUID VF token. Required= for VF when PF is owned " "by another VFIO driver"); -#ifdef CONFIG_IOMMUFD object_class_property_set_description(klass, /* 9.0 */ "iommufd", "Set host IOMMUFD backend device= "); -#endif object_class_property_set_description(klass, /* 9.1 */ "x-device-dirty-page-tracking", "Disable device dirty page track= ing and use " --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789360; cv=none; d=zohomail.com; s=zohoarc; b=XR5/x+FzvzRNvkgW2ROKIZE1f2wXZMnO36VbPPGtbjg+BEkZpQ3kha3DHoOTLv9C2CZD78kAqNw8v3zyZZv93cVVHdl0qySnW8b6N9fpFpWBqP79X85DVKCvlzXOY/CeRUAHlNvMBkGSvbMGwwtO2QyGzuspc5e1aZGlzeIQqxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789360; 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=DIr7OAH7jPAt9Ijrp8ig0Z4yyQ3WYxYoNGA5UcPZCys=; b=kBDmPM8wWKqoYzbgPirPFK7ZXjGOCbanm8ELXrwkj118qCQ3TvKMKTCEb3DQX+4wg1XDQBi5tsi00zPFtxZg257EzThKnqETDvrr1zjLj2x4bjQk0fgqtmpzxaXsYWFJoHp3uR6dpd5Zdjxn2+un6vEdnPvxZs92Era8nx/RdX4= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789360778619.8475103444644; Tue, 21 Apr 2026 09:36:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE4e-0004nu-TK; Tue, 21 Apr 2026 12:35:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE40-0004aI-OS for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE3t-0007NJ-LI for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:02 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-22-aUIqYgI-N2ervx99N1yH0g-1; Tue, 21 Apr 2026 12:34:54 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 773E81955F29; Tue, 21 Apr 2026 16:34:53 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C125D1956056; Tue, 21 Apr 2026 16:34:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789296; 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=DIr7OAH7jPAt9Ijrp8ig0Z4yyQ3WYxYoNGA5UcPZCys=; b=c6bV1Daa7qVe58VW2QYE6r6lK//xNxe7C3uWbdTdEfMY3ZSEgmzMHlUi7wYfni9umO6EzN 3QITOyJTC9siFbiez1AmZRIJ5iTLHH/M/TuGY4r8V5s301nspf7KGpZqVL1hKf3K1fSxvQ /mFku3Vg0Qx0/EcPFej3EIQUCScm90k= X-MC-Unique: aUIqYgI-N2ervx99N1yH0g-1 X-Mimecast-MFC-AGG-ID: aUIqYgI-N2ervx99N1yH0g_1776789293 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Pierrick Bouvier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 05/14] hw/vfio/pci.c: eradicate CONFIG_KVM Date: Tue, 21 Apr 2026 18:34:29 +0200 Message-ID: <20260421163438.3447280-6-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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, 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: 1776789362731154100 From: Pierrick Bouvier We just need to add kvm_enabled() guard when calling concerned functions, but no need to extract those kvm functions since they are not using any kvm specific types that would not be visible at compilation time. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier Reviewed-by: C=C3=A9dric Le Goater Tested-by: C=C3=A9dric Le Goater Tested-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260318174733.1717643-6-pierrick.= bouvier@linaro.org Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 1f1f3aaad9a901a087ecad1b5c46e8756b3a6339..b2a07f6bb4217bcacead194ce75= b359b1896ef3a 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -152,7 +152,6 @@ void vfio_pci_intx_eoi(VFIODevice *vbasedev) =20 static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) { -#ifdef CONFIG_KVM PCIDevice *pdev =3D PCI_DEVICE(vdev); int irq_fd =3D event_notifier_get_fd(&vdev->intx.interrupt); =20 @@ -206,14 +205,10 @@ fail: qemu_set_fd_handler(irq_fd, vfio_intx_interrupt, NULL, vdev); vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); return false; -#else - return true; -#endif } =20 static bool vfio_cpr_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) { -#ifdef CONFIG_KVM if (vdev->no_kvm_intx || !kvm_irqfds_enabled() || vdev->intx.route.mode !=3D PCI_INTX_ENABLED || !kvm_resamplefds_enabled()) { @@ -236,14 +231,10 @@ static bool vfio_cpr_intx_enable_kvm(VFIOPCIDevice *v= dev, Error **errp) vdev->intx.kvm_accel =3D true; trace_vfio_intx_enable_kvm(vdev->vbasedev.name); return true; -#else - return true; -#endif } =20 static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) { -#ifdef CONFIG_KVM PCIDevice *pdev =3D PCI_DEVICE(vdev); =20 if (!vdev->intx.kvm_accel) { @@ -277,7 +268,6 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); =20 trace_vfio_intx_disable_kvm(vdev->vbasedev.name); -#endif } =20 static void vfio_intx_update(VFIOPCIDevice *vdev, PCIINTxRoute *route) @@ -287,7 +277,9 @@ static void vfio_intx_update(VFIOPCIDevice *vdev, PCIIN= TxRoute *route) trace_vfio_intx_update(vdev->vbasedev.name, vdev->intx.route.irq, route->irq); =20 - vfio_intx_disable_kvm(vdev); + if (kvm_enabled()) { + vfio_intx_disable_kvm(vdev); + } =20 vdev->intx.route =3D *route; =20 @@ -295,7 +287,7 @@ static void vfio_intx_update(VFIOPCIDevice *vdev, PCIIN= TxRoute *route) return; } =20 - if (!vfio_intx_enable_kvm(vdev, &err)) { + if (kvm_enabled() && !vfio_intx_enable_kvm(vdev, &err)) { warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } =20 @@ -350,16 +342,14 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Err= or **errp) vdev->intx.pin =3D pin - 1; /* Pin A (1) -> irq[0] */ pci_config_set_interrupt_pin(pdev->config, pin); =20 -#ifdef CONFIG_KVM /* * Only conditional to avoid generating error messages on platforms * where we won't actually use the result anyway. */ - if (kvm_irqfds_enabled() && kvm_resamplefds_enabled()) { + if (kvm_enabled() && kvm_irqfds_enabled() && kvm_resamplefds_enabled()= ) { vdev->intx.route =3D pci_device_route_intx_to_irq(pdev, vdev->intx.pin); } -#endif =20 if (!vfio_notifier_init(vdev, &vdev->intx.interrupt, "intx-interrupt",= 0, errp)) { @@ -370,7 +360,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error= **errp) =20 =20 if (cpr_is_incoming()) { - if (!vfio_cpr_intx_enable_kvm(vdev, &err)) { + if (kvm_enabled() && !vfio_cpr_intx_enable_kvm(vdev, &err)) { warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } goto skip_signaling; @@ -383,7 +373,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error= **errp) return false; } =20 - if (!vfio_intx_enable_kvm(vdev, &err)) { + if (kvm_enabled() && !vfio_intx_enable_kvm(vdev, &err)) { warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } =20 @@ -400,7 +390,9 @@ static void vfio_intx_disable(VFIOPCIDevice *vdev) int fd; =20 timer_del(vdev->intx.mmap_timer); - vfio_intx_disable_kvm(vdev); + if (kvm_enabled()) { + vfio_intx_disable_kvm(vdev); + } vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); vdev->intx.pending =3D false; pci_irq_deassert(pdev); --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789382; cv=none; d=zohomail.com; s=zohoarc; b=bRfjo+XlDmSwBm2LDiZPYO1c61ghi0XMYytpNxMexuJkQrCL6L0PhvO6QuijozHXYq5YZKkDi//lCMJdgGYSE452J7O8ACkghgWgGepM9QJbRGupkDZ2XcWQmOYy1W29WU7yVz08tQvnUPFv3xasHzNeuV//VXtFZg8m+i0o5E4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789382; 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=cvBU61n2B89u85FKlMgnQ17RNhMy5hcD6Akp2nfyRoA=; b=BbqEnYDRKr5cKJp+QzgWuLEF0bx2/87uRMQfM4A7o+aWKmxiK6u/nHVQzb873DJjxuErUPz9JfwvUdMCrrb67/xKzdCtXVcYjvBE5mJFMTU1YiX8m8dqwa9O1fCA0Iq8JZHz2gzLTUs3wxcnl1k6Vi+1LbxX5ylSv1VCXu2YWAQ= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789382098945.8927252675472; Tue, 21 Apr 2026 09:36:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE59-000502-7h; Tue, 21 Apr 2026 12:36:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE47-0004gs-HK for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE40-0007Nv-Au for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:07 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-r9FM4NScPRiJaSxMlktAGQ-1; Tue, 21 Apr 2026 12:34:56 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BA5FF19560AA; Tue, 21 Apr 2026 16:34:55 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E6B751956095; Tue, 21 Apr 2026 16:34:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789300; 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=cvBU61n2B89u85FKlMgnQ17RNhMy5hcD6Akp2nfyRoA=; b=iAauU1zzTm8qP9NqCQMo3mt64JPiBUTR6K2iz4MScyPwQ9BzZtGDtLq6aq4qmRQegvNpl6 GPT8hFd1ImYRXnqm085xJyJ/SsWSTITLpQ6SO00BaxqmzosEDqofxGJNUhbq4ROKfKuI09 +Mqt7ZdRlKETeH/9zuM0VQyQBdI46h4= X-MC-Unique: r9FM4NScPRiJaSxMlktAGQ-1 X-Mimecast-MFC-AGG-ID: r9FM4NScPRiJaSxMlktAGQ_1776789295 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Pierrick Bouvier , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 06/14] hw/vfio/ap.c: use full path for target specific header Date: Tue, 21 Apr 2026 18:34:30 +0200 Message-ID: <20260421163438.3447280-7-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1776789408808154100 From: Pierrick Bouvier In addition, we fix target/s390x/kvm/kvm_s390x.h cpu-qom include also. Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier Tested-by: C=C3=A9dric Le Goater Tested-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260318174733.1717643-7-pierrick.= bouvier@linaro.org Signed-off-by: C=C3=A9dric Le Goater --- target/s390x/kvm/kvm_s390x.h | 2 +- hw/vfio/ap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/target/s390x/kvm/kvm_s390x.h b/target/s390x/kvm/kvm_s390x.h index 649dae5948a6e4069beb526d6be1df667d68e292..7b1cce3e60d5a407239d4055bbf= 0196edbc8c686 100644 --- a/target/s390x/kvm/kvm_s390x.h +++ b/target/s390x/kvm/kvm_s390x.h @@ -10,7 +10,7 @@ #ifndef KVM_S390X_H #define KVM_S390X_H =20 -#include "cpu-qom.h" +#include "target/s390x/cpu-qom.h" =20 struct kvm_s390_irq; =20 diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index be20d7e7dc67f21363863f8c6d8b2a7cdedb8762..276ae8c207bf2a1d7a0d5c0fc7f= 2ef98cec695d1 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -25,7 +25,7 @@ #include "qemu/module.h" #include "qemu/option.h" #include "qemu/config-file.h" -#include "kvm/kvm_s390x.h" +#include "target/s390x/kvm/kvm_s390x.h" #include "migration/vmstate.h" #include "hw/core/qdev-properties.h" #include "hw/s390x/ap-bridge.h" --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789583; cv=none; d=zohomail.com; s=zohoarc; b=L0f//ey5MH1oeV79PiG8epdyagXemSzQMmmnKSzC4H/uDNeXvtZXffDaB2t886pmGFJ6G4aKHex5pFS9Uk72Gg908L+lqW63DAhBU+tMOUarS6QRn5EIRkIQ9dTJ7F/+9+QBQgiQ+1dhCT2Tlg8t4+icTzxyzoIv9JclG5urjgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789583; 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=HN7usOvOD5JXKjKE5SLWxOEK8n3ue3orhToutZspIB8=; b=c0hlyMQPjf0A59Lrzs+venivh5jECYbNrR00jz1MqF4Gy6Gk0Dotj3FGoNShbPCMYjkyTftzFx8P3oOjvT4n5d+edoEYTU64QJLIHo3FbHkfG/hzpEGnyTOBW7k6FVhOIPZX52WwY69XqtQ9mo5BwLOVfZxmi7P4FNrRWcbmh7E= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17767895831351.5408294199417014; Tue, 21 Apr 2026 09:39:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE5L-0005La-Ki; Tue, 21 Apr 2026 12:36:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE47-0004gq-ET for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE40-0007OI-7y for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:06 -0400 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-711-Acl5_vHmM_KoYKEhIFPDCQ-1; Tue, 21 Apr 2026 12:34:59 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 203AC18003F6; Tue, 21 Apr 2026 16:34:58 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 350DB19560AB; Tue, 21 Apr 2026 16:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789302; 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=HN7usOvOD5JXKjKE5SLWxOEK8n3ue3orhToutZspIB8=; b=SMmeLHcB9oz77wkunKL1jdduRpqu3GzTlYMBjLxpCsnZ9jd/wwnR2jD0qBsxSftQUbt3So 6xYHNGMG5LmRr9CRAETxRkwvpQyoB0XrHuvPPlvD4ZMN9vrhOiDxxfQ4/fRjq+J4i33G5f BAcC2hlwUx2nnjs3RsBDN5NAdZWCuUQ= X-MC-Unique: Acl5_vHmM_KoYKEhIFPDCQ-1 X-Mimecast-MFC-AGG-ID: Acl5_vHmM_KoYKEhIFPDCQ_1776789298 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Pierrick Bouvier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 07/14] hw/vfio/spapr.c: extract vfio_spapr_kvm_attach_tce to hw/vfio/kvm-spapr.c Date: Tue, 21 Apr 2026 18:34:31 +0200 Message-ID: <20260421163438.3447280-8-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1776789585828158500 From: Pierrick Bouvier Since this function needs kvm specific types, we need to extract in another file and link it only for KVM builds. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier Reviewed-by: C=C3=A9dric Le Goater Tested-by: C=C3=A9dric Le Goater Tested-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260318174733.1717643-8-pierrick.= bouvier@linaro.org Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/kvm-spapr.h | 12 ++++++++++++ hw/vfio/kvm-spapr.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ hw/vfio/kvm-stubs.c | 8 ++++++++ hw/vfio/spapr.c | 30 ++++------------------------- hw/vfio/meson.build | 1 + 5 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 hw/vfio/kvm-spapr.h create mode 100644 hw/vfio/kvm-spapr.c diff --git a/hw/vfio/kvm-spapr.h b/hw/vfio/kvm-spapr.h new file mode 100644 index 0000000000000000000000000000000000000000..b1f68c686a7defbed94cc4c0d56= b786bc436ed89 --- /dev/null +++ b/hw/vfio/kvm-spapr.h @@ -0,0 +1,12 @@ +/* + * VFIO sPAPR KVM specific functions + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "hw/vfio/vfio-container.h" +#include "qapi/error.h" + +bool vfio_spapr_kvm_attach_tce(VFIOContainer *bcontainer, + MemoryRegionSection *section, + Error **errp); diff --git a/hw/vfio/kvm-spapr.c b/hw/vfio/kvm-spapr.c new file mode 100644 index 0000000000000000000000000000000000000000..ad71c5a85e273fbe8df9fda71ba= 21c7df171914d --- /dev/null +++ b/hw/vfio/kvm-spapr.c @@ -0,0 +1,47 @@ +/* + * VFIO sPAPR KVM specific functions + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include +#include +#include + +#include "hw/vfio/vfio-container-legacy.h" +#include "hw/vfio/kvm-spapr.h" +#include "qapi/error.h" +#include "trace.h" +#include "vfio-helpers.h" + +bool vfio_spapr_kvm_attach_tce(VFIOContainer *bcontainer, + MemoryRegionSection *section, + Error **errp) +{ + VFIOLegacyContainer *container =3D VFIO_IOMMU_LEGACY(bcontainer); + VFIOGroup *group; + IOMMUMemoryRegion *iommu_mr =3D IOMMU_MEMORY_REGION(section->mr); + struct kvm_vfio_spapr_tce param; + struct kvm_device_attr attr =3D { + .group =3D KVM_DEV_VFIO_GROUP, + .attr =3D KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE, + .addr =3D (uint64_t)(unsigned long)¶m, + }; + + if (!memory_region_iommu_get_attr(iommu_mr, IOMMU_ATTR_SPAPR_TCE_FD, + ¶m.tablefd)) { + QLIST_FOREACH(group, &container->group_list, container_next) { + param.groupfd =3D group->fd; + if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { + error_setg_errno(errp, errno, + "vfio: failed GROUP_SET_SPAPR_TCE for " + "KVM VFIO device %d and group fd %d", + param.tablefd, param.groupfd); + return false; + } + trace_vfio_spapr_group_attach(param.groupfd, param.tablefd); + } + } + return true; +} diff --git a/hw/vfio/kvm-stubs.c b/hw/vfio/kvm-stubs.c index 5a489d1b7110a5564054398cc354bb806ac39334..78c51b9915559ba3c328cb3bcc0= d9e2896269f9f 100644 --- a/hw/vfio/kvm-stubs.c +++ b/hw/vfio/kvm-stubs.c @@ -6,6 +6,7 @@ =20 #include "qemu/osdep.h" =20 +#include "hw/vfio/kvm-spapr.h" #include "hw/vfio/vfio-device.h" #include "qapi/error.h" #include "vfio-helpers.h" @@ -24,3 +25,10 @@ int vfio_kvm_device_del_fd(int fd, Error **errp) { return 0; } + +bool vfio_spapr_kvm_attach_tce(VFIOContainer *bcontainer, + MemoryRegionSection *section, + Error **errp) +{ + g_assert_not_reached(); +} diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index a9f093c357057eaa07378c77c86da096fe9f6297..42690e4323d20915c55591129d9= fce0ae46b0cf3 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -16,6 +16,7 @@ #include "system/address-spaces.h" =20 #include "hw/vfio/vfio-container-legacy.h" +#include "hw/vfio/kvm-spapr.h" #include "hw/core/hw-error.h" #include "qemu/error-report.h" #include "qapi/error.h" @@ -406,33 +407,10 @@ vfio_spapr_container_add_section_window(VFIOContainer= *bcontainer, vfio_host_win_add(scontainer, section->offset_within_address_space, section->offset_within_address_space + int128_get64(section->size) - 1, pgsize); -#ifdef CONFIG_KVM - if (kvm_enabled()) { - VFIOGroup *group; - IOMMUMemoryRegion *iommu_mr =3D IOMMU_MEMORY_REGION(section->mr); - struct kvm_vfio_spapr_tce param; - struct kvm_device_attr attr =3D { - .group =3D KVM_DEV_VFIO_GROUP, - .attr =3D KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE, - .addr =3D (uint64_t)(unsigned long)¶m, - }; - - if (!memory_region_iommu_get_attr(iommu_mr, IOMMU_ATTR_SPAPR_TCE_F= D, - ¶m.tablefd)) { - QLIST_FOREACH(group, &container->group_list, container_next) { - param.groupfd =3D group->fd; - if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr))= { - error_setg_errno(errp, errno, - "vfio: failed GROUP_SET_SPAPR_TCE for= " - "KVM VFIO device %d and group fd %d", - param.tablefd, param.groupfd); - return false; - } - trace_vfio_spapr_group_attach(param.groupfd, param.tablefd= ); - } - } + if (kvm_enabled() && !vfio_spapr_kvm_attach_tce(bcontainer, section, e= rrp)) { + return false; } -#endif + return true; } =20 diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index 6c00a7f51bbe79d8e45d828a11d4deecf21512be..bab5f2b7f1555eed452e7a91b8a= 8984bb1f262c6 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -10,6 +10,7 @@ vfio_ss.add(files( vfio_ss.add(when: 'CONFIG_KVM', if_true: files('kvm-helpers.c')) stub_ss.add(files('kvm-stubs.c')) vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c')) +vfio_ss.add(when: ['CONFIG_KVM', 'CONFIG_PSERIES'], if_true: files('kvm-sp= apr.c')) vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( 'pci-quirks.c', 'pci.c', --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789393; cv=none; d=zohomail.com; s=zohoarc; b=GbXE6dcHED1AUutd7tT3V4W5ULKkW6WIxwqT+76dNodWiNK2oPWD7KwogBSkHj4I54TJ1Dc4Ag/2azw85Qc4c8lgzdeBnq3eqj0nGKk3YYtUZxG2ysPIR+7m5nXD0pzHm+NN+6Ih8qYTtwtjRfRcOlmRfdLR+6JLg/1f6Yqzd9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789393; 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=CloDXS87FzNb/tGDNxSs0nfz/bnNIma8jJQqA/HUL5E=; b=I9Hjr1go5AbNV3Rj+47kVFZNrDgkPQNMKFVJhQak2z4yqHLWee3Q3iS/lFWAHwp1FyQmUI5Dds8sSAJ4S/oaBq4mSOsvNJ2yAnFAAxMom32ZT6omBa9LkzDPWcq7dCQYWHMOcsxR9Y9NletgCDJHJlKTzEkw9TbvTTQSjGzJT2o= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789393651595.5591674646996; Tue, 21 Apr 2026 09:36:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE5B-00057n-NP; Tue, 21 Apr 2026 12:36:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE4A-0004is-Gw for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE43-0007Ph-No for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:11 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-645-S7pSl4BwN2uapiB-0zofXA-1; Tue, 21 Apr 2026 12:35:01 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 36D26195607B; Tue, 21 Apr 2026 16:35:00 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7669D1956095; Tue, 21 Apr 2026 16:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789305; 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=CloDXS87FzNb/tGDNxSs0nfz/bnNIma8jJQqA/HUL5E=; b=ic+WGWCcm7AKfK5QRoURYY6aH77458WtT3jYLe1JkmdpWrQXBr3+XEhzNcd0T8mLDBXFql G3ohg64luwbpgEnK50pMRe+aG0CJbVAdrW8mczolhuPRAFWMjfkc0NLcHlbtl3D5TNUa59 k2rEgLtmZ1Gw6r7fPIo1e8eieCoBhYc= X-MC-Unique: S7pSl4BwN2uapiB-0zofXA-1 X-Mimecast-MFC-AGG-ID: S7pSl4BwN2uapiB-0zofXA_1776789300 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Pierrick Bouvier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 08/14] hw/vfio: all vfio files can now be common files Date: Tue, 21 Apr 2026 18:34:32 +0200 Message-ID: <20260421163438.3447280-9-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1776789395145154100 From: Pierrick Bouvier Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Pierrick Bouvier Tested-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20260318174733.1717643-9-pierrick.= bouvier@linaro.org Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index bab5f2b7f1555eed452e7a91b8a8984bb1f262c6..fa0ea6ecf0e1478e88769af73da= 1badc9daca921 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -20,7 +20,7 @@ vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'= )) vfio_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files('igd.c')) stub_ss.add(files('igd-stubs.c')) =20 -specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss) +system_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss) =20 system_ss.add(when: 'CONFIG_VFIO', if_true: files( 'cpr.c', --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789382; cv=none; d=zohomail.com; s=zohoarc; b=JM56usCE1B3KobG62rcCWS4mdksHneRev6WIqu1AnwSyxZHJUOCYmEJ7jVI4DOHAMB7r4rywh0yC8Nh6Uv4yG2hRkGoc/JUSTAoi10Qvr5dUVUI0nldkrPLtj7gILwUFF0ywDXz9gF6VN0XASr7NdpYQbRb8mTmN/G8l4lECV+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789382; 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=JEJgk+MKJNK8mlBm/c9Qv5iXP3OMPqQpBC+KEvaYTJ8=; b=ntm3dk645DAzlgpWCTxaqBU2LgLPPrYKaIu5Sg/QaY8jy0XmAKtOicGYqJdOU8Ff3Zuds+ihE7nNVl+QgkfQ+DfNf2fy0dj0XduUeHM7nzbVokv2qcaKkDfdr3HmNRX7f7/2B3DnOUawBjk3MCunsg26tl4ofIvbJYNIXjTVgn8= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789382673996.0538653297751; Tue, 21 Apr 2026 09:36:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE58-0004zQ-Hy; Tue, 21 Apr 2026 12:36:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE4F-0004lc-Rq for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE47-0007QU-8d for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:16 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-StKAelf2MLu6nrgatzt8Fg-1; Tue, 21 Apr 2026 12:35:03 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9D9AB1956080; Tue, 21 Apr 2026 16:35:02 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A67441956095; Tue, 21 Apr 2026 16:35:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789307; 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=JEJgk+MKJNK8mlBm/c9Qv5iXP3OMPqQpBC+KEvaYTJ8=; b=ZpkLAKPj5I/7QLs4lcKm0h0SaaxkyB6dNXg214lXmEPXQ2tIt29OnAcNLdziex3nnyAvRz vdOr5VSmteIeCHlQiV2zbkSqHYyxBQ8CyYdGFbXqqmv1UGdlDEKQuqeKi1hbdtv6dxGJz3 aNxxerV9Oai5R9hjezTisT180bEMdGg= X-MC-Unique: StKAelf2MLu6nrgatzt8Fg-1 X-Mimecast-MFC-AGG-ID: StKAelf2MLu6nrgatzt8Fg_1776789302 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 09/14] iommufd: Rename all the idev and idevc variables to hiod and hiodc Date: Tue, 21 Apr 2026 18:34:33 +0200 Message-ID: <20260421163438.3447280-10-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1776789384303158500 From: Zhenzhong Duan We used idev and idevc naming for HostIOMMUDeviceIOMMUFD and corresponding class variables which followed the iommufd_device naming in linux kernel. This is mixed with the hiod naming for base type HostIOMMUDevice. Rename HostIOMMUDeviceIOMMUFD* to hiodi* for consistency in QEMU. No functional change intended. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20260401080354.1347212-1-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/arm/smmuv3-accel.h | 2 +- include/system/iommufd.h | 12 ++--- backends/iommufd.c | 26 +++++------ hw/arm/smmuv3-accel.c | 93 +++++++++++++++++++------------------ hw/i386/intel_iommu_accel.c | 44 +++++++++--------- hw/vfio/container-legacy.c | 10 ++-- hw/vfio/iommufd.c | 24 +++++----- 7 files changed, 107 insertions(+), 104 deletions(-) diff --git a/hw/arm/smmuv3-accel.h b/hw/arm/smmuv3-accel.h index dba6c71de5269a2223a9048e703ae2f829513f8e..908a13cbcc6b44c1d524221c489= 695176bc07ed1 100644 --- a/hw/arm/smmuv3-accel.h +++ b/hw/arm/smmuv3-accel.h @@ -34,7 +34,7 @@ typedef struct SMMUS1Hwpt { =20 typedef struct SMMUv3AccelDevice { SMMUDevice sdev; - HostIOMMUDeviceIOMMUFD *idev; + HostIOMMUDeviceIOMMUFD *hiodi; SMMUS1Hwpt *s1_hwpt; IOMMUFDVdev *vdev; QLIST_ENTRY(SMMUv3AccelDevice) next; diff --git a/include/system/iommufd.h b/include/system/iommufd.h index 7062944fe61d161fa6ca1c0cff1be879e6449955..2925d116acdf285ae3ff9968a01= 8a924be6138db 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -136,7 +136,7 @@ struct HostIOMMUDeviceIOMMUFDClass { * * Mandatory callback. * - * @idev: host IOMMU device backed by IOMMUFD backend. + * @hiodi: host IOMMU device backed by IOMMUFD backend. * * @hwpt_id: ID of IOMMUFD hardware page table. * @@ -144,7 +144,7 @@ struct HostIOMMUDeviceIOMMUFDClass { * * Returns: true on success, false on failure. */ - bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *idev, uint32_t hwpt_id, + bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t hwpt_id, Error **errp); /** * @detach_hwpt: detach host IOMMU device from IOMMUFD hardware page t= able. @@ -152,17 +152,17 @@ struct HostIOMMUDeviceIOMMUFDClass { * * Mandatory callback. * - * @idev: host IOMMU device backed by IOMMUFD backend. + * @hiodi: host IOMMU device backed by IOMMUFD backend. * * @errp: pass an Error out when attachment fails. * * Returns: true on success, false on failure. */ - bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *idev, Error **errp); + bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, Error **errp); }; =20 -bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev, +bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t hwpt_id, Error **errp); -bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev, +bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, Error **errp); #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index e1fee16acf2e15ad1e9066aa32a270bb3945b52d..410b0443707a2baed91ddf221ba= e4df0f2376c8a 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -538,24 +538,24 @@ bool iommufd_backend_alloc_veventq(IOMMUFDBackend *be= , uint32_t viommu_id, return true; } =20 -bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev, +bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t hwpt_id, Error **errp) { - HostIOMMUDeviceIOMMUFDClass *idevc =3D - HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(idev); + HostIOMMUDeviceIOMMUFDClass *hiodic =3D + HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi); =20 - g_assert(idevc->attach_hwpt); - return idevc->attach_hwpt(idev, hwpt_id, errp); + g_assert(hiodic->attach_hwpt); + return hiodic->attach_hwpt(hiodi, hwpt_id, errp); } =20 -bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev, +bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, Error **errp) { - HostIOMMUDeviceIOMMUFDClass *idevc =3D - HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(idev); + HostIOMMUDeviceIOMMUFDClass *hiodic =3D + HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi); =20 - g_assert(idevc->detach_hwpt); - return idevc->detach_hwpt(idev, errp); + g_assert(hiodic->detach_hwpt); + return hiodic->detach_hwpt(hiodi, errp); } =20 static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **er= rp) @@ -591,10 +591,10 @@ static bool hiod_iommufd_get_pasid_info(HostIOMMUDevi= ce *hiod, =20 static void hiod_iommufd_class_init(ObjectClass *oc, const void *data) { - HostIOMMUDeviceClass *hioc =3D HOST_IOMMU_DEVICE_CLASS(oc); + HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_CLASS(oc); =20 - hioc->get_cap =3D hiod_iommufd_get_cap; - hioc->get_pasid_info =3D hiod_iommufd_get_pasid_info; + hiodc->get_cap =3D hiod_iommufd_get_cap; + hiodc->get_pasid_info =3D hiod_iommufd_get_pasid_info; }; =20 static const TypeInfo types[] =3D { diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c index 65c2f44880a06402049ec9ba885c7eb082419f79..3630078751ca544d023398ed088= 047c6c561c1ca 100644 --- a/hw/arm/smmuv3-accel.c +++ b/hw/arm/smmuv3-accel.c @@ -129,16 +129,16 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s, } =20 static bool -smmuv3_accel_hw_compatible(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *idev, +smmuv3_accel_hw_compatible(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *hiodi, Error **errp) { struct iommu_hw_info_arm_smmuv3 info; uint32_t data_type; uint64_t caps; =20 - if (!iommufd_backend_get_device_info(idev->iommufd, idev->devid, &data= _type, - &info, sizeof(info), &caps, NULL, - errp)) { + if (!iommufd_backend_get_device_info(hiodi->iommufd, hiodi->devid, + &data_type, &info, sizeof(info), = &caps, + NULL, errp)) { return false; } =20 @@ -182,15 +182,15 @@ static bool smmuv3_accel_alloc_vdev(SMMUv3AccelDevice *accel_dev, int sid, Error **err= p) { SMMUv3AccelState *accel =3D accel_dev->s_accel; - HostIOMMUDeviceIOMMUFD *idev =3D accel_dev->idev; + HostIOMMUDeviceIOMMUFD *hiodi =3D accel_dev->hiodi; IOMMUFDVdev *vdev =3D accel_dev->vdev; uint32_t vdevice_id; =20 - if (!idev || vdev) { + if (!hiodi || vdev) { return true; } =20 - if (!iommufd_backend_alloc_vdev(idev->iommufd, idev->devid, + if (!iommufd_backend_alloc_vdev(hiodi->iommufd, hiodi->devid, accel->viommu->viommu_id, sid, &vdevice_id, errp)) { return false; @@ -209,7 +209,7 @@ smmuv3_accel_dev_alloc_translate(SMMUv3AccelDevice *acc= el_dev, STE *ste, { uint64_t ste_0 =3D (uint64_t)ste->word[0] | (uint64_t)ste->word[1] << = 32; uint64_t ste_1 =3D (uint64_t)ste->word[2] | (uint64_t)ste->word[3] << = 32; - HostIOMMUDeviceIOMMUFD *idev =3D accel_dev->idev; + HostIOMMUDeviceIOMMUFD *hiodi =3D accel_dev->hiodi; SMMUv3AccelState *accel =3D accel_dev->s_accel; struct iommu_hwpt_arm_smmuv3 nested_data =3D { .ste =3D { @@ -220,7 +220,7 @@ smmuv3_accel_dev_alloc_translate(SMMUv3AccelDevice *acc= el_dev, STE *ste, uint32_t hwpt_id =3D 0, flags =3D 0; SMMUS1Hwpt *s1_hwpt; =20 - if (!iommufd_backend_alloc_hwpt(idev->iommufd, idev->devid, + if (!iommufd_backend_alloc_hwpt(hiodi->iommufd, hiodi->devid, accel->viommu->viommu_id, flags, IOMMU_HWPT_DATA_ARM_SMMUV3, sizeof(nested_data), &nested_data, @@ -242,7 +242,7 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevic= e *sdev, int sid, .inval_ste_allowed =3D true}; SMMUv3AccelState *accel =3D s->s_accel; SMMUv3AccelDevice *accel_dev; - HostIOMMUDeviceIOMMUFD *idev; + HostIOMMUDeviceIOMMUFD *hiodi; uint32_t config, hwpt_id =3D 0; SMMUS1Hwpt *s1_hwpt =3D NULL; const char *type; @@ -257,7 +257,7 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevic= e *sdev, int sid, return true; } =20 - idev =3D accel_dev->idev; + hiodi =3D accel_dev->hiodi; if (!smmuv3_accel_alloc_vdev(accel_dev, sid, errp)) { return false; } @@ -300,9 +300,9 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevic= e *sdev, int sid, return false; } =20 - if (!host_iommu_device_iommufd_attach_hwpt(idev, hwpt_id, errp)) { + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) { if (s1_hwpt) { - iommufd_backend_free_id(idev->iommufd, s1_hwpt->hwpt_id); + iommufd_backend_free_id(hiodi->iommufd, s1_hwpt->hwpt_id); g_free(s1_hwpt); } return false; @@ -310,7 +310,7 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevic= e *sdev, int sid, =20 /* Free the previous s1_hwpt */ if (accel_dev->s1_hwpt) { - iommufd_backend_free_id(idev->iommufd, accel_dev->s1_hwpt->hwpt_id= ); + iommufd_backend_free_id(hiodi->iommufd, accel_dev->s1_hwpt->hwpt_i= d); g_free(accel_dev->s1_hwpt); } =20 @@ -524,7 +524,7 @@ free_veventq: } =20 static bool -smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *idev, +smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *hiodi, Error **errp) { SMMUv3AccelState *accel =3D s->s_accel; @@ -534,11 +534,11 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDe= viceIOMMUFD *idev, struct iommu_hwpt_arm_smmuv3 abort_data =3D { .ste =3D { SMMU_STE_VALID, 0x0ULL }, }; - uint32_t s2_hwpt_id =3D idev->hwpt_id; + uint32_t s2_hwpt_id =3D hiodi->hwpt_id; uint32_t viommu_id, hwpt_id; IOMMUFDViommu *viommu; =20 - if (!iommufd_backend_alloc_viommu(idev->iommufd, idev->devid, + if (!iommufd_backend_alloc_viommu(hiodi->iommufd, hiodi->devid, IOMMU_VIOMMU_TYPE_ARM_SMMUV3, s2_hwpt_id, &viommu_id, errp)) { return false; @@ -547,21 +547,21 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDe= viceIOMMUFD *idev, viommu =3D g_new0(IOMMUFDViommu, 1); viommu->viommu_id =3D viommu_id; viommu->s2_hwpt_id =3D s2_hwpt_id; - viommu->iommufd =3D idev->iommufd; + viommu->iommufd =3D hiodi->iommufd; accel->viommu =3D viommu; =20 /* * Pre-allocate HWPTs for S1 bypass and abort cases. These will be att= ached * later for guest STEs or GBPAs that require bypass or abort configur= ation. */ - if (!iommufd_backend_alloc_hwpt(idev->iommufd, idev->devid, viommu_id, + if (!iommufd_backend_alloc_hwpt(hiodi->iommufd, hiodi->devid, viommu_i= d, 0, IOMMU_HWPT_DATA_ARM_SMMUV3, sizeof(abort_data), &abort_data, &accel->abort_hwpt_id, errp)) { goto free_viommu; } =20 - if (!iommufd_backend_alloc_hwpt(idev->iommufd, idev->devid, viommu_id, + if (!iommufd_backend_alloc_hwpt(hiodi->iommufd, hiodi->devid, viommu_i= d, 0, IOMMU_HWPT_DATA_ARM_SMMUV3, sizeof(bypass_data), &bypass_data, &accel->bypass_hwpt_id, errp)) { @@ -575,7 +575,7 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDevi= ceIOMMUFD *idev, =20 /* Attach a HWPT based on SMMUv3 GBPA.ABORT value */ hwpt_id =3D smmuv3_accel_gbpa_hwpt(s, accel); - if (!host_iommu_device_iommufd_attach_hwpt(idev, hwpt_id, errp)) { + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) { goto free_veventq; } return true; @@ -583,11 +583,11 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDe= viceIOMMUFD *idev, free_veventq: smmuv3_accel_free_veventq(accel); free_bypass_hwpt: - iommufd_backend_free_id(idev->iommufd, accel->bypass_hwpt_id); + iommufd_backend_free_id(hiodi->iommufd, accel->bypass_hwpt_id); free_abort_hwpt: - iommufd_backend_free_id(idev->iommufd, accel->abort_hwpt_id); + iommufd_backend_free_id(hiodi->iommufd, accel->abort_hwpt_id); free_viommu: - iommufd_backend_free_id(idev->iommufd, viommu->viommu_id); + iommufd_backend_free_id(hiodi->iommufd, viommu->viommu_id); g_free(viommu); accel->viommu =3D NULL; return false; @@ -596,20 +596,20 @@ free_viommu: static bool smmuv3_accel_set_iommu_device(PCIBus *bus, void *opaque, int d= evfn, HostIOMMUDevice *hiod, Error **e= rrp) { - HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(hiod); + HostIOMMUDeviceIOMMUFD *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(hiod); SMMUState *bs =3D opaque; SMMUv3State *s =3D ARM_SMMUV3(bs); SMMUPciBus *sbus =3D smmu_get_sbus(bs, bus); SMMUv3AccelDevice *accel_dev =3D smmuv3_accel_get_dev(bs, sbus, bus, d= evfn); =20 - if (!idev) { + if (!hiodi) { return true; } =20 - if (accel_dev->idev) { - if (accel_dev->idev !=3D idev) { - error_setg(errp, "Device already has an associated idev 0x%x", - idev->devid); + if (accel_dev->hiodi) { + if (accel_dev->hiodi !=3D hiodi) { + error_setg(errp, "Device already has an associated hiodi 0x%x", + hiodi->devid); return false; } return true; @@ -619,7 +619,7 @@ static bool smmuv3_accel_set_iommu_device(PCIBus *bus, = void *opaque, int devfn, * Check the host SMMUv3 associated with the dev is compatible with the * QEMU SMMUv3 accel. */ - if (!smmuv3_accel_hw_compatible(s, idev, errp)) { + if (!smmuv3_accel_hw_compatible(s, hiodi, errp)) { return false; } =20 @@ -627,17 +627,17 @@ static bool smmuv3_accel_set_iommu_device(PCIBus *bus= , void *opaque, int devfn, goto done; } =20 - if (!smmuv3_accel_alloc_viommu(s, idev, errp)) { - error_append_hint(errp, "Unable to alloc vIOMMU: idev devid 0x%x: = ", - idev->devid); + if (!smmuv3_accel_alloc_viommu(s, hiodi, errp)) { + error_append_hint(errp, "Unable to alloc vIOMMU: hiodi devid 0x%x:= ", + hiodi->devid); return false; } =20 done: - accel_dev->idev =3D idev; + accel_dev->hiodi =3D hiodi; accel_dev->s_accel =3D s->s_accel; QLIST_INSERT_HEAD(&s->s_accel->device_list, accel_dev, next); - trace_smmuv3_accel_set_iommu_device(devfn, idev->devid); + trace_smmuv3_accel_set_iommu_device(devfn, hiodi->devid); return true; } =20 @@ -646,7 +646,7 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus= , void *opaque, { SMMUState *bs =3D opaque; SMMUPciBus *sbus =3D g_hash_table_lookup(bs->smmu_pcibus_by_busptr, bu= s); - HostIOMMUDeviceIOMMUFD *idev; + HostIOMMUDeviceIOMMUFD *hiodi; SMMUv3AccelDevice *accel_dev; SMMUv3AccelState *accel; IOMMUFDVdev *vdev; @@ -662,16 +662,16 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *b= us, void *opaque, } =20 accel_dev =3D container_of(sdev, SMMUv3AccelDevice, sdev); - idev =3D accel_dev->idev; + hiodi =3D accel_dev->hiodi; accel =3D accel_dev->s_accel; /* Re-attach the default s2 hwpt id */ - if (!host_iommu_device_iommufd_attach_hwpt(idev, idev->hwpt_id, NULL))= { - error_report("Unable to attach the default HW pagetable: idev devi= d " - "0x%x", idev->devid); + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_id, NULL= )) { + error_report("Unable to attach the default HW pagetable: hiodi dev= id " + "0x%x", hiodi->devid); } =20 if (accel_dev->s1_hwpt) { - iommufd_backend_free_id(accel_dev->idev->iommufd, + iommufd_backend_free_id(accel_dev->hiodi->iommufd, accel_dev->s1_hwpt->hwpt_id); g_free(accel_dev->s1_hwpt); accel_dev->s1_hwpt =3D NULL; @@ -684,10 +684,10 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *b= us, void *opaque, accel_dev->vdev =3D NULL; } =20 - accel_dev->idev =3D NULL; + accel_dev->hiodi =3D NULL; accel_dev->s_accel =3D NULL; QLIST_REMOVE(accel_dev, next); - trace_smmuv3_accel_unset_iommu_device(devfn, idev->devid); + trace_smmuv3_accel_unset_iommu_device(devfn, hiodi->devid); =20 if (QLIST_EMPTY(&accel->device_list)) { smmuv3_accel_free_viommu(accel); @@ -879,10 +879,11 @@ bool smmuv3_accel_attach_gbpa_hwpt(SMMUv3State *s, Er= ror **errp) =20 hwpt_id =3D smmuv3_accel_gbpa_hwpt(s, accel); QLIST_FOREACH(accel_dev, &accel->device_list, next) { - if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->idev, hwpt_i= d, + if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi, hwpt_= id, &local_err)) { error_append_hint(&local_err, "Failed to attach GBPA hwpt %u f= or " - "idev devid %u", hwpt_id, accel_dev->idev->d= evid); + "hiodi devid %u", hwpt_id, + accel_dev->hiodi->devid); error_report_err(local_err); local_err =3D NULL; all_ok =3D false; diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 67d54849f2f08187629fca5e2c081f8dd003b6b2..ed3793602bc51bbce0f4428bfab= f6ad1772f3d13 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -69,7 +69,7 @@ VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace= *as) return NULL; } =20 -static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev, +static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, VTDPASIDEntry *pe, uint32_t *fs_hwpt_id, Error **errp) { @@ -81,27 +81,27 @@ static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *= idev, vtd.addr_width =3D vtd_pe_get_fs_aw(pe); vtd.pgtbl_addr =3D (uint64_t)vtd_pe_get_fspt_base(pe); =20 - 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); + return iommufd_backend_alloc_hwpt(hiodi->iommufd, hiodi->devid, + hiodi->hwpt_id, 0, IOMMU_HWPT_DATA_V= TD_S1, + sizeof(vtd), &vtd, fs_hwpt_id, errp); } =20 -static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev, +static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, VTDAddressSpace *vtd_as) { if (!vtd_as->fs_hwpt_id) { return; } - iommufd_backend_free_id(idev->iommufd, vtd_as->fs_hwpt_id); + iommufd_backend_free_id(hiodi->iommufd, vtd_as->fs_hwpt_id); vtd_as->fs_hwpt_id =3D 0; } =20 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); + HostIOMMUDeviceIOMMUFD *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->= hiod); VTDPASIDEntry *pe =3D &vtd_as->pasid_cache_entry.pasid_entry; - uint32_t hwpt_id =3D idev->hwpt_id; + uint32_t hwpt_id =3D hiodi->hwpt_id; bool ret; =20 /* @@ -116,21 +116,21 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDev= ice *vtd_hiod, } =20 if (vtd_pe_pgtt_is_fst(pe)) { - if (!vtd_create_fs_hwpt(idev, pe, &hwpt_id, errp)) { + if (!vtd_create_fs_hwpt(hiodi, pe, &hwpt_id, errp)) { return false; } } =20 - 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); + ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp); + trace_vtd_device_attach_hwpt(hiodi->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); + vtd_destroy_old_fs_hwpt(hiodi, 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); + iommufd_backend_free_id(hiodi->iommufd, hwpt_id); } =20 return ret; @@ -139,27 +139,28 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDev= ice *vtd_hiod, 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); + HostIOMMUDeviceIOMMUFD *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->= hiod); IntelIOMMUState *s =3D vtd_as->iommu_state; uint32_t pasid =3D vtd_as->pasid; bool ret; =20 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); + ret =3D host_iommu_device_iommufd_detach_hwpt(hiodi, errp); + trace_vtd_device_detach_hwpt(hiodi->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 =3D host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_i= d, + errp); + trace_vtd_device_reattach_def_hwpt(hiodi->devid, pasid, hiodi->hwp= t_id, ret); } =20 if (ret) { - vtd_destroy_old_fs_hwpt(idev, vtd_as); + vtd_destroy_old_fs_hwpt(hiodi, vtd_as); } =20 return ret; @@ -211,13 +212,14 @@ static void vtd_flush_host_piotlb_locked(gpointer key= , gpointer value, did =3D VTD_SM_PASID_ENTRY_DID(&pc_entry->pasid_entry); =20 if (piotlb_info->domain_id =3D=3D did && piotlb_info->pasid =3D=3D PAS= ID_0) { - HostIOMMUDeviceIOMMUFD *idev =3D + HostIOMMUDeviceIOMMUFD *hiodi =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; =20 - if (!iommufd_backend_invalidate_cache(idev->iommufd, vtd_as->fs_hw= pt_id, + if (!iommufd_backend_invalidate_cache(hiodi->iommufd, + vtd_as->fs_hwpt_id, IOMMU_HWPT_INVALIDATE_DATA_V= TD_S1, sizeof(*cache), &entry_num, = cache, &local_err)) { diff --git a/hw/vfio/container-legacy.c b/hw/vfio/container-legacy.c index 625f151364c060135076cd19537810bbe61ab998..d301b27aa652964d4f5f2cb5bd2= 2de69048eb337 100644 --- a/hw/vfio/container-legacy.c +++ b/hw/vfio/container-legacy.c @@ -1244,12 +1244,12 @@ static void vfio_iommu_legacy_instance_init(Object = *obj) =20 static void hiod_legacy_vfio_class_init(ObjectClass *oc, const void *data) { - HostIOMMUDeviceClass *hioc =3D HOST_IOMMU_DEVICE_CLASS(oc); + HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_CLASS(oc); =20 - hioc->realize =3D hiod_legacy_vfio_realize; - hioc->get_cap =3D hiod_legacy_vfio_get_cap; - hioc->get_iova_ranges =3D hiod_legacy_vfio_get_iova_ranges; - hioc->get_page_size_mask =3D hiod_legacy_vfio_get_page_size_mask; + hiodc->realize =3D hiod_legacy_vfio_realize; + hiodc->get_cap =3D hiod_legacy_vfio_get_cap; + hiodc->get_iova_ranges =3D hiod_legacy_vfio_get_iova_ranges; + hiodc->get_page_size_mask =3D hiod_legacy_vfio_get_page_size_mask; }; =20 static const TypeInfo types[] =3D { diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 3e33dfbb35652376d1e285485221f27fcea84d16..399b36aa752ebe24d5ea7eb4d0a= 991785c51e642 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -917,19 +917,19 @@ static void vfio_iommu_iommufd_class_init(ObjectClass= *klass, const void *data) }; =20 static bool -host_iommu_device_iommufd_vfio_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev, +host_iommu_device_iommufd_vfio_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t hwpt_id, Error **errp) { - VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(idev)->agent; + VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(hiodi)->agent; =20 return !iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt_id, errp); } =20 static bool -host_iommu_device_iommufd_vfio_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev, +host_iommu_device_iommufd_vfio_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, Error **errp) { - VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(idev)->agent; + VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(hiodi)->agent; =20 return iommufd_cdev_detach_ioas_hwpt(vbasedev, errp); } @@ -938,7 +938,7 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *= hiod, void *opaque, Error **errp) { VFIODevice *vdev =3D opaque; - HostIOMMUDeviceIOMMUFD *idev; + HostIOMMUDeviceIOMMUFD *hiodi; HostIOMMUDeviceCaps *caps =3D &hiod->caps; VendorCaps *vendor_caps =3D &caps->vendor_caps; enum iommu_hw_info_type type; @@ -958,10 +958,10 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice= *hiod, void *opaque, caps->hw_caps =3D hw_caps; caps->max_pasid_log2 =3D max_pasid_log2; =20 - idev =3D HOST_IOMMU_DEVICE_IOMMUFD(hiod); - idev->iommufd =3D vdev->iommufd; - idev->devid =3D vdev->devid; - idev->hwpt_id =3D vdev->hwpt->hwpt_id; + hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(hiod); + hiodi->iommufd =3D vdev->iommufd; + hiodi->devid =3D vdev->devid; + hiodi->hwpt_id =3D vdev->hwpt->hwpt_id; =20 return true; } @@ -988,14 +988,14 @@ hiod_iommufd_vfio_get_page_size_mask(HostIOMMUDevice = *hiod) static void hiod_iommufd_vfio_class_init(ObjectClass *oc, const void *data) { HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_CLASS(oc); - HostIOMMUDeviceIOMMUFDClass *idevc =3D HOST_IOMMU_DEVICE_IOMMUFD_CLASS= (oc); + HostIOMMUDeviceIOMMUFDClass *hiodic =3D HOST_IOMMU_DEVICE_IOMMUFD_CLAS= S(oc); =20 hiodc->realize =3D hiod_iommufd_vfio_realize; hiodc->get_iova_ranges =3D hiod_iommufd_vfio_get_iova_ranges; hiodc->get_page_size_mask =3D hiod_iommufd_vfio_get_page_size_mask; =20 - idevc->attach_hwpt =3D host_iommu_device_iommufd_vfio_attach_hwpt; - idevc->detach_hwpt =3D host_iommu_device_iommufd_vfio_detach_hwpt; + hiodic->attach_hwpt =3D host_iommu_device_iommufd_vfio_attach_hwpt; + hiodic->detach_hwpt =3D host_iommu_device_iommufd_vfio_detach_hwpt; }; =20 static const TypeInfo types[] =3D { --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789439; cv=none; d=zohomail.com; s=zohoarc; b=nybqcXEfnS0kE04Weq1MVbPGEdLi1YIl51Orsr4dQ9P4K86ZF4YWIK879a1sLGeAxtU12zrCBOH0xnRTJFKrTh4jL4fL81ZXCIZKxNMgpmBWDdm/dQUi1WzSAHGpG8DY4iiz8+zIO0Hu4c/9Xn08G/yzwn96Q5Waet7uH4KBpcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789439; 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=VvTNqp++Rdp2v3KRck3Tf7+xvqfTdXk5NH7kjqmKGWw=; b=A3S/k6NUrf+RJ/yMHSDWTn/kYwGdQfJ6PuQLjCDboy3k7K/6b4DJ2wCRKeiEGIklEJz8GeeTvuVfO/UJqlieEdYKISjjFD0/65gejOEmE5QiXBh0A+fvKCDBP4/drXvN5lz0cSPOY9I/At7qy5jmaJRsDJweOtdTcDlLwDAM/7k= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789439069146.30917117721106; Tue, 21 Apr 2026 09:37:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE5N-0005eB-HP; Tue, 21 Apr 2026 12:36:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE4B-0004jb-M1 for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE47-0007Qa-92 for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:13 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-5Utkm1NqOlqx8OgkUovcTg-1; Tue, 21 Apr 2026 12:35:06 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0CFE719560AA; Tue, 21 Apr 2026 16:35:05 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 193701956095; Tue, 21 Apr 2026 16:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789307; 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=VvTNqp++Rdp2v3KRck3Tf7+xvqfTdXk5NH7kjqmKGWw=; b=agN1j8Kij/1KOslJruKoNThLQtgca0YOmx04NtZVtVG2ws2t1g4d3WpQyv4LTlN8P9jK8/ Nl8IoUNMSojilF8q8sM5QH5p6YlW4mh9T/xqhRHrPBWUVhC812gWuPFYBmU5kozKrfsJJG uf7056QnkqO7fY5lyfztDwwqiNiMNyc= X-MC-Unique: 5Utkm1NqOlqx8OgkUovcTg-1 X-Mimecast-MFC-AGG-ID: 5Utkm1NqOlqx8OgkUovcTg_1776789305 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Shameer Kolothum , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 10/14] hw/vfio/iommufd: Control dirty tracking for nesting parent HWPT Date: Tue, 21 Apr 2026 18:34:34 +0200 Message-ID: <20260421163438.3447280-11-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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, 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: 1776789440617158500 From: Shameer Kolothum QEMU smmuv3 accel does not support live migration yet, so dirty tracking for the nesting parent HWPT is not useful. Also, nested vIOMMU use cases can break on some platforms. For example, SMMUv3 with HTTU may advertise dirty tracking capability, but the kernel supports it only for stage-1. Requesting dirty tracking for a nesting parent HWPT (stage-2) can fail. Add a vIOMMU flag to explicitly request dirty tracking for the nesting parent HWPT. For nested cases, dirty tracking is enabled only when requested by the vIOMMU. Non-nested cases and Intel vIOMMU keep the existing behavior. Fixes: fc6dafb98cec ("hw/arm/smmuv3: Implement get_viommu_cap() callback") Signed-off-by: Shameer Kolothum Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20260401084133.56266-1-skolothumth= o@nvidia.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/core/iommu.h | 2 ++ include/hw/vfio/vfio-device.h | 1 + hw/i386/intel_iommu.c | 7 +++++-- hw/vfio/device.c | 11 +++++++++++ hw/vfio/iommufd.c | 11 +++++++++-- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/hw/core/iommu.h b/include/hw/core/iommu.h index 86af315c153763d4d217a2e255c3f7aced228e91..cd59a367ceb9517885a5a8c14a4= 0af3404e99832 100644 --- a/include/hw/core/iommu.h +++ b/include/hw/core/iommu.h @@ -21,6 +21,8 @@ enum viommu_flags { /* vIOMMU needs nesting parent HWPT to create nested HWPT */ VIOMMU_FLAG_WANT_NESTING_PARENT =3D BIT_ULL(0), VIOMMU_FLAG_PASID_SUPPORTED =3D BIT_ULL(1), + /* vIOMMU needs dirty tracking on the nesting parent HWPT for nested u= se */ + VIOMMU_FLAG_WANT_NESTING_DIRTY_TRACKING =3D BIT_ULL(2), }; =20 /* Host IOMMU quirks. Extracted from host IOMMU capabilities */ diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 828a31c006ec9fc372760fee023da31b0e7acc4b..a95c5bf50302a7394582dcc493d= 96aef00b47dc8 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -268,6 +268,7 @@ 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_viommu_flags_want_nesting_dirty(VFIODevice *vbasedev); bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODevice *vbasedev, uint32_t type, void *caps, uint32_t size); diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index f395fa248c009c663be281774c8455ee3b85d8a2..b784c5f10aebbd3fe1f1c332c4e= cc5aecc2b9136 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4825,9 +4825,12 @@ static void vtd_dev_unset_iommu_device(PCIBus *bus, = void *opaque, int devfn) static uint64_t vtd_get_viommu_flags(void *opaque) { IntelIOMMUState *s =3D opaque; - uint64_t flags; + uint64_t flags =3D 0; =20 - flags =3D s->fsts ? VIOMMU_FLAG_WANT_NESTING_PARENT : 0; + if (s->fsts) { + flags =3D VIOMMU_FLAG_WANT_NESTING_PARENT | + VIOMMU_FLAG_WANT_NESTING_DIRTY_TRACKING; + } =20 return flags; } diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 973fc35b59d4bdaa34c0f2773ec78df0f151dfa2..8f7ae919a55dd9e08bdd072eee3= 3f5b46a91aa2a 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -522,6 +522,17 @@ void vfio_device_unprepare(VFIODevice *vbasedev) vbasedev->bcontainer =3D NULL; } =20 +bool vfio_device_get_viommu_flags_want_nesting_dirty(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_DIRTY_TRACKING); + } + return false; +} + bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev) { VFIOPCIDevice *vdev =3D vfio_pci_from_vfio_device(vbasedev); diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 399b36aa752ebe24d5ea7eb4d0a991785c51e642..df148a49a762b1f6b05d548cb9f= 9b0413b743439 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -352,6 +352,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, ERRP_GUARD(); IOMMUFDBackend *iommufd =3D vbasedev->iommufd; VFIOContainer *bcontainer =3D VFIO_IOMMU(container); + bool viommu_nesting, viommu_nesting_dirty; uint32_t type, flags =3D 0; uint64_t hw_caps; VendorCaps caps; @@ -405,8 +406,14 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, return false; } =20 + viommu_nesting =3D vfio_device_get_viommu_flags_want_nesting(vbasedev); + viommu_nesting_dirty =3D + vfio_device_get_viommu_flags_want_nesting_dirty(vbasedev); + if (hw_caps & IOMMU_HW_CAP_DIRTY_TRACKING) { - flags =3D IOMMU_HWPT_ALLOC_DIRTY_TRACKING; + if (!viommu_nesting || viommu_nesting_dirty) { + flags |=3D IOMMU_HWPT_ALLOC_DIRTY_TRACKING; + } } =20 /* @@ -414,7 +421,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, * 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)) { + if (viommu_nesting) { flags |=3D IOMMU_HWPT_ALLOC_NEST_PARENT; =20 if (vfio_device_get_host_iommu_quirk_bypass_ro(vbasedev, type, --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789573; cv=none; d=zohomail.com; s=zohoarc; b=i3IIgS8Une+QOrusIm5tdHOiIIflq5xj3kpoanDsEtABV/LHqhMLzAEDL1AMAThAXC8+4FLTUsKwBP2UrnNP6kDByOOiMotehlxuHWqZz73xaqWIPf4ejRykjE8DOFX5N9dsz6WgoYRFZ4g3KnsTYGIn2o6O8d/KKWlpxOkM4GM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789573; 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=6R4y+QhhrybEffprDmtR2R9k97KuSAVNSeD24Kw/+u0=; b=d+/JqsC1ZU7o7HtIzXYKHmYUjQ11TAFQGz+8lqGTAWOpLH+QoAoCPNAY05btdYkKT85nU3gMCi17/UkJCuZKCN9xPic88fongDRZv6olCE6ADgOZ/ir3OBfKLYydKEPNHQds0Yn3ik0//2fEItQSTJbzqYYmGc6aOppXqqGTFC4= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789573348319.53924974722906; Tue, 21 Apr 2026 09:39:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE5E-00058d-8c; Tue, 21 Apr 2026 12:36:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE4B-0004jZ-DF for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE47-0007Qh-8Z for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:13 -0400 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-330-rI_rZ5xoOkSrGHVvojfEnQ-1; Tue, 21 Apr 2026 12:35:07 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EB6361800370; Tue, 21 Apr 2026 16:35:06 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7B89D1956095; Tue, 21 Apr 2026 16:35:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789309; 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=6R4y+QhhrybEffprDmtR2R9k97KuSAVNSeD24Kw/+u0=; b=b49koB74J2TAHlqX/D3Zy+70K/Lr0QPula5AZSTgPSWfMwFIdCK4FGOufitR1yw8RWQF19 /dUGbRn33KnhANf0i5dbyLqV+2HaHBIBqgGoC4flGSMg7ts7lpYlVi2PzyogPzb5WHCluP 5J0LOxgAV4NjK/jR+UIn8YOpwTjwgRY= X-MC-Unique: rI_rZ5xoOkSrGHVvojfEnQ-1 X-Mimecast-MFC-AGG-ID: rI_rZ5xoOkSrGHVvojfEnQ_1776789307 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?= , John Levon Subject: [PULL 11/14] vfio: Add VFIO I/O backend capability flags for feature support Date: Tue, 21 Apr 2026 18:34:35 +0200 Message-ID: <20260421163438.3447280-12-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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, 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: 1776789574003154100 Different VFIO I/O backends support different features. For example, the kernel VFIO backend supports DMA-BUF creation, while vfio-user does not. Currently, this is handled by attempting the operation and checking for -ENOTTY, which can lead to misleading warnings when a feature is simply not supported by a particular backend. Introduce a capability flags mechanism in VFIODeviceIOOps that allows backends to explicitly advertise which features they support. Callers can check these capabilities before attempting operations, avoiding spurious errors and warnings. Cc: John Levon Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20260409114312.1704062-1-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-device.h | 13 +++++++++++++ hw/vfio/device.c | 2 ++ hw/vfio/region.c | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index a95c5bf50302a7394582dcc493d96aef00b47dc8..380a55d6e5ea280c8f44016c7a8= a1dcb8f4c00fe 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -172,12 +172,25 @@ typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODe= viceList; extern VFIODeviceList vfio_device_list; =20 #ifdef CONFIG_LINUX +/* + * VFIO backend I/O operation capabilities + */ +#define VFIO_IO_CAP_DMA_BUF (1ULL << 0) + /* * How devices communicate with the server. The default option is through * ioctl() to the kernel VFIO driver, but vfio-user can use a socket to a = remote * process. */ struct VFIODeviceIOOps { + /** + * @capabilities + * + * Bitmask of VFIO_IO_CAP_* flags indicating which features this + * backend supports. + */ + uint64_t capabilities; + /** * @device_feature * diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 8f7ae919a55dd9e08bdd072eee33f5b46a91aa2a..3ffd69a579b8ac135ef729d3d83= 6c8545e36786b 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -648,6 +648,8 @@ static int vfio_device_io_region_write(VFIODevice *vbas= edev, uint8_t index, } =20 static VFIODeviceIOOps vfio_device_io_ops_ioctl =3D { + .capabilities =3D VFIO_IO_CAP_DMA_BUF, + .device_feature =3D vfio_device_io_device_feature, .get_region_info =3D vfio_device_io_get_region_info, .get_irq_info =3D vfio_device_io_get_irq_info, diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 47fdc2df349b65c6be6c9605b7a38a4e367f0475..0342ca712acd0ad846685115c29= 432c15aa966a0 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -293,6 +293,11 @@ static bool vfio_region_create_dma_buf(VFIORegion *reg= ion, Error **errp) size_t total_size; int i, ret; =20 + /* Check if backend supports DMA-BUF creation */ + if (!(vbasedev->io_ops->capabilities & VFIO_IO_CAP_DMA_BUF)) { + return true; + } + total_size =3D sizeof(*feature) + sizeof(*dma_buf) + sizeof(struct vfio_region_dma_range) * region->nr_mmaps; feature =3D g_malloc0(total_size); --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789469; cv=none; d=zohomail.com; s=zohoarc; b=l3A04O8urRDtSGr4GLu/jrz8wttkULZFoGIlS2b682LTd3TUGj/XCoW2OO/7szTYGLkbRAf5Asdz0KhC1A4qguGakCX1i0lM4XD3CHwpkInSluH/W7YqIMkULzHmhT5LbvnDtdOI7k6a1fhwxPgMCGBN5dnS4h4Bg4NgchVBrdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789469; 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=WyHtqI2Ue/MKNZUMYUPQJtTao0sjJcCWoBG4JpXT4Eo=; b=L3VtsSxoeJWygu0URdHL2YKHU/R2D0Q1P9m0j3EHiwsA/97v7rHA+lvd8qlLfVg5avNiFFbswjwxz8JfWVfbFH2mNHWvVyhjCu1gxeHdsQSoPuxmHGFHPrk68v+9WgPoE21El5+dhgTXpf+hYvNp8OaXaZqLGC7bojHAb09w44U= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789469614748.4125369203259; Tue, 21 Apr 2026 09:37:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE5E-00058q-Uo; Tue, 21 Apr 2026 12:36:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE4N-0004mJ-Aa for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE4B-0007Ra-KX for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:18 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-cvLt6BlhMzydZj7DCD-t6w-1; Tue, 21 Apr 2026 12:35:09 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D81651956088; Tue, 21 Apr 2026 16:35:08 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 67F731956095; Tue, 21 Apr 2026 16:35:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789313; 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=WyHtqI2Ue/MKNZUMYUPQJtTao0sjJcCWoBG4JpXT4Eo=; b=cr48ujhSyacv+ZcS8xOeirtD096/W2rfj6hio3VnyacH45u/80pl0agaSTm/WLY/+g7ZDb XZPzWMHyME3NHo/yycnTpoX2dx/FSCd3avZ6TqiSoT1uzMA384X0M71uTGjkfMMqDl24QZ dBDBZbxaoiqI/0go1HHc5a80L7hssjw= X-MC-Unique: cvLt6BlhMzydZj7DCD-t6w-1 X-Mimecast-MFC-AGG-ID: cvLt6BlhMzydZj7DCD-t6w_1776789308 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , John Levon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 12/14] vfio-user: support VFIO_USER_DEVICE_FEATURE Date: Tue, 21 Apr 2026 18:34:36 +0200 Message-ID: <20260421163438.3447280-13-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1776789472292154100 From: John Levon Plumb through vfio_device_get_feature to the vfio-user server. Note that we translate EINVAL into ENOTTY, as the existing generic vfio code is expecting the latter to mean "unsupported". As part of adding a trace point, clean up the trace file. Signed-off-by: John Levon Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20260410085716.877185-2-john.levon= @nutanix.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio-user/protocol.h | 12 +++++++++++ hw/vfio-user/device.c | 42 +++++++++++++++++++++++++++++++++++++++ hw/vfio-user/trace-events | 23 +++++++++++---------- 3 files changed, 67 insertions(+), 10 deletions(-) diff --git a/hw/vfio-user/protocol.h b/hw/vfio-user/protocol.h index 3249a4a6b62af95e3718ed5053bbf310cd08c024..2a0c31e7c57f8ed86681ebd96b2= 0df3e32792dec 100644 --- a/hw/vfio-user/protocol.h +++ b/hw/vfio-user/protocol.h @@ -40,6 +40,7 @@ enum vfio_user_command { VFIO_USER_DEVICE_RESET =3D 13, VFIO_USER_DIRTY_PAGES =3D 14, VFIO_USER_REGION_WRITE_MULTI =3D 15, + VFIO_USER_DEVICE_FEATURE =3D 16, VFIO_USER_MAX, }; =20 @@ -239,4 +240,15 @@ typedef struct { VFIOUserWROne wrs[VFIO_USER_MULTI_MAX]; } VFIOUserWRMulti; =20 +/* + * VFIO_USER_DEVICE_FEATURE + * imported from struct vfio_device_feature + */ +typedef struct { + VFIOUserHdr hdr; + uint32_t argsz; + uint32_t flags; + char data[]; +} VFIOUserDeviceFeature; + #endif /* VFIO_USER_PROTOCOL_H */ diff --git a/hw/vfio-user/device.c b/hw/vfio-user/device.c index 64ef35b3209429f7158d4ea79f095a5f16950d77..b8d2b7c1a84bb1914a71fdccbbd= ff675373cef3b 100644 --- a/hw/vfio-user/device.c +++ b/hw/vfio-user/device.c @@ -74,6 +74,47 @@ void vfio_user_device_reset(VFIOUserProxy *proxy) } } =20 +static int +vfio_user_device_io_device_feature(VFIODevice *vbasedev, + struct vfio_device_feature *feature) +{ + g_autofree VFIOUserDeviceFeature *msgp =3D NULL; + int size =3D sizeof(VFIOUserHdr) + feature->argsz; + VFIOUserProxy *proxy =3D vbasedev->proxy; + Error *local_err =3D NULL; + + msgp =3D g_malloc0(size); + + vfio_user_request_msg(&msgp->hdr, VFIO_USER_DEVICE_FEATURE, size, 0); + + memcpy(&msgp->argsz, &feature->argsz, feature->argsz); + + if (!vfio_user_send_wait(proxy, &msgp->hdr, NULL, size, &local_err)) { + error_prepend(&local_err, "%s: ", __func__); + error_report_err(local_err); + return -EFAULT; + } + + if (msgp->hdr.flags & VFIO_USER_ERROR) { + /* + * Client expects ENOTTY for "not supported", but the protocol may + * return EINVAL (which should only occur in the case the feature = isn't + * actually supported on the server). + */ + if (msgp->hdr.error_reply =3D=3D EINVAL) { + return -ENOTTY; + } + + return -msgp->hdr.error_reply; + } + + memcpy(feature, &msgp->argsz, feature->argsz); + + trace_vfio_user_device_io_device_feature(msgp->argsz, msgp->flags); + + return 0; +} + static int vfio_user_get_region_info(VFIOUserProxy *proxy, struct vfio_region_info *info, VFIOUserFDs *fds) @@ -432,6 +473,7 @@ static int vfio_user_device_io_region_write(VFIODevice = *vbasedev, uint8_t index, * Socket-based io_ops */ VFIODeviceIOOps vfio_user_device_io_ops_sock =3D { + .device_feature =3D vfio_user_device_io_device_feature, .get_region_info =3D vfio_user_device_io_get_region_info, .get_irq_info =3D vfio_user_device_io_get_irq_info, .set_irqs =3D vfio_user_device_io_set_irqs, diff --git a/hw/vfio-user/trace-events b/hw/vfio-user/trace-events index abb67f4c119af533a77ad04e383fa027e5aaa684..503e1c82d43a7d9361b1e5d4879= 29ecc5a8a83da 100644 --- a/hw/vfio-user/trace-events +++ b/hw/vfio-user/trace-events @@ -2,19 +2,22 @@ # # SPDX-License-Identifier: GPL-2.0-or-later =20 -# common.c +# container.c +vfio_user_dma_map(uint64_t iova, uint64_t size, uint64_t off, uint32_t fla= gs, bool async_ops) " iova 0x%"PRIx64" size 0x%"PRIx64" off 0x%"PRIx64" fla= gs 0x%x async_ops %d" +vfio_user_dma_unmap(uint64_t iova, uint64_t size, uint32_t flags, bool as= ync_ops) " iova 0x%"PRIx64" size 0x%"PRIx64" flags 0x%x async_ops %d" + +# device.c +vfio_user_device_io_device_feature(uint32_t argsz, uint32_t flags) " argsz= 0x%x flags 0x%x" +vfio_user_get_info(uint32_t nregions, uint32_t nirqs) " #regions %d #irqs = %d" +vfio_user_get_irq_info(uint32_t index, uint32_t flags, uint32_t count) " i= ndex %d flags 0x%x count %d" +vfio_user_set_irqs(uint32_t index, uint32_t start, uint32_t count, uint32_= t flags) " index %d start %d count %d flags 0x%x" +vfio_user_get_region_info(uint32_t index, uint32_t flags, uint64_t size) "= index %d flags 0x%x size 0x%"PRIx64 +vfio_user_region_rw(uint32_t region, uint64_t off, uint32_t count) " regio= n %d offset 0x%"PRIx64" count %d" + +# proxy.c vfio_user_recv_hdr(const char *name, uint16_t id, uint16_t cmd, uint32_t s= ize, uint32_t flags) " (%s) id 0x%x cmd 0x%x size 0x%x flags 0x%x" vfio_user_recv_read(uint16_t id, int read) " id 0x%x read 0x%x" vfio_user_recv_request(uint16_t cmd) " command 0x%x" vfio_user_send_write(uint16_t id, int wrote) " id 0x%x wrote 0x%x" vfio_user_version(uint16_t major, uint16_t minor, const char *caps) " majo= r %d minor %d caps: %s" -vfio_user_get_info(uint32_t nregions, uint32_t nirqs) " #regions %d #irqs = %d" -vfio_user_get_region_info(uint32_t index, uint32_t flags, uint64_t size) "= index %d flags 0x%x size 0x%"PRIx64 -vfio_user_region_rw(uint32_t region, uint64_t off, uint32_t count) " regio= n %d offset 0x%"PRIx64" count %d" -vfio_user_get_irq_info(uint32_t index, uint32_t flags, uint32_t count) " i= ndex %d flags 0x%x count %d" -vfio_user_set_irqs(uint32_t index, uint32_t start, uint32_t count, uint32_= t flags) " index %d start %d count %d flags 0x%x" vfio_user_wrmulti(const char *s, uint64_t wr_cnt) " %s count 0x%"PRIx64 - -# container.c -vfio_user_dma_map(uint64_t iova, uint64_t size, uint64_t off, uint32_t fla= gs, bool async_ops) " iova 0x%"PRIx64" size 0x%"PRIx64" off 0x%"PRIx64" fla= gs 0x%x async_ops %d" -vfio_user_dma_unmap(uint64_t iova, uint64_t size, uint32_t flags, bool as= ync_ops) " iova 0x%"PRIx64" size 0x%"PRIx64" flags 0x%x async_ops %d" --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789383; cv=none; d=zohomail.com; s=zohoarc; b=lhkPERJwIMIdWQabxv5dpjI/iS8kqbF9afrN1HXlimS90wbeIIkM5xPIcgMfBOsBii38Dbh+EQvgltOy1hsheJJc4tzqFlluSD9NC/Fbfe1zNrLt1WORHOcCdGjuZo5FdD7KNtiT5TXVqznIAkSLM2lS6dEBt2bG9PpEnqd7NQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789383; 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=Ag3As0f4fL9HtrGb1OP7FYrdzOBSvJ9BHuESWcySACw=; b=d4IuldR9Y5F/5iNi5QlVrn/1UoTIplL6cmLISfeWWAFz39zgkDxWR2VnqHeSKowChV/JaR/rzxtq3UK+ZIR2H5EKBsYahdaesyyTRg0fGnt6YUBtNAyzbImF05tcTwWxFTUpZCC13dy8xNuurvIB9R8LkMBZE6l9GG65/eGhdSI= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789383397577.2197436808409; Tue, 21 Apr 2026 09:36:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE51-0004w0-LK; Tue, 21 Apr 2026 12:36:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE4X-0004nx-8f for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE4L-0007SW-Bf for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:30 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-146-dqXlcsoAMZqSUc9-63DYTw-1; Tue, 21 Apr 2026 12:35:12 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 230EB19560B3; Tue, 21 Apr 2026 16:35:11 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 538A51956095; Tue, 21 Apr 2026 16:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789315; 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=Ag3As0f4fL9HtrGb1OP7FYrdzOBSvJ9BHuESWcySACw=; b=huGWL8eV1u4suTY2X7OPusHMPqvfY/MVcOnJOgUpih/W6oTKhMdtYAkSbavUe8t7D91seK mY8onPHpzXvaUqEr8pF23BEccpEuYkAD6+83DjH8o/CqRvz7tEbba8T3yx4h5Q0+Wgm7KK jsc2jY9o6B2UPaplDt0Up125Bs3RF+A= X-MC-Unique: dqXlcsoAMZqSUc9-63DYTw-1 X-Mimecast-MFC-AGG-ID: dqXlcsoAMZqSUc9-63DYTw_1776789311 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , John Levon , Patrick Mooney , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 13/14] vfio-user: correct protocol for DMA reads/writes Date: Tue, 21 Apr 2026 18:34:37 +0200 Message-ID: <20260421163438.3447280-14-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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, 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: 1776789384348158501 From: John Levon The "count" parameter in the DMA write reply should be 8 bytes in size. Reported-by: Patrick Mooney Signed-off-by: John Levon Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20260410085716.877185-3-john.levon= @nutanix.com Signed-off-by: C=C3=A9dric Le Goater --- docs/interop/vfio-user.rst | 2 +- hw/vfio-user/protocol.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/interop/vfio-user.rst b/docs/interop/vfio-user.rst index 303fc13d6ec4c32c32bd95604c75239342d85062..d4766487ea6d0ee021316890d44= 3814957cf6284 100644 --- a/docs/interop/vfio-user.rst +++ b/docs/interop/vfio-user.rst @@ -1463,7 +1463,7 @@ Reply +=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D+ | address | 0 | 8 | +---------+--------+----------+ -| count | 8 | 4 | +| count | 8 | 8 | +---------+--------+----------+ =20 * *address* is the client DMA memory address being accessed. diff --git a/hw/vfio-user/protocol.h b/hw/vfio-user/protocol.h index 2a0c31e7c57f8ed86681ebd96b20df3e32792dec..c478d1353f9d618ef8c202cd28c= d638aeed3bd57 100644 --- a/hw/vfio-user/protocol.h +++ b/hw/vfio-user/protocol.h @@ -210,7 +210,7 @@ typedef struct { typedef struct { VFIOUserHdr hdr; uint64_t offset; - uint32_t count; + uint64_t count; char data[]; } VFIOUserDMARW; =20 --=20 2.53.0 From nobody Sat May 30 20:11:35 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=1776789437; cv=none; d=zohomail.com; s=zohoarc; b=EF/STUox1cZDyq4LlMp0htPDhJ/vLq/xtk9+LzDFqSjb6MWQEjm3JZferlSv218TavzVUWmvWYXj/cmkMdHLl8qyG5/ebVsC1G8zj06UJTwG148ENajLXqY9pjQeium7ZKJQlC/SjvpkTTa+YDBRl/oj/CXuAtiqxqJPLT6rI2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776789437; 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=L4boacDBWXxI5RCVqYYkYH11QOnnmQygqQshHe9V5xU=; b=YEYzzVHT3WJJwmwtXiuNyT1j+FmA9Zqv2GmCUYBqFOkngHNmoxgwrmcom5ch4mbgiH8CvYlffK2+smdeirkmtw36XFKP7CeD1o7SIVmR/Vw1duNelJhPHDiRh+xUeyZEy5fUw+KdSozI4ZrLSg1O3HKofW62ovEAtt1l0MmPhDY= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776789437027892.4246254144235; Tue, 21 Apr 2026 09:37:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wFE5P-0005qC-VF; Tue, 21 Apr 2026 12:36:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE4f-0004qG-CF for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wFE4V-0007UD-5K for qemu-devel@nongnu.org; Tue, 21 Apr 2026 12:35:41 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-308-kl6Dm1SGPSGekxQN19MjgQ-1; Tue, 21 Apr 2026 12:35:14 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 817DA19560AD; Tue, 21 Apr 2026 16:35:13 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.70]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BBAB71956095; Tue, 21 Apr 2026 16:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776789317; 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=L4boacDBWXxI5RCVqYYkYH11QOnnmQygqQshHe9V5xU=; b=fncuQVJRDaTBWjn7CDKq7vGkRQXiPqfCCvw+zgJkyv7OKtUY+fQskfv8XwvpWdUZmYfyYL wdLUed9mrWOd78oLyLQtCj+XOQj4Fgvq8G2o2HoBARzY5ug75w8bapMBCXSl6HrbXoncTF t+qV91WQcSDBRfIXcrnlbZ2BbTxYum0= X-MC-Unique: kl6Dm1SGPSGekxQN19MjgQ-1 X-Mimecast-MFC-AGG-ID: kl6Dm1SGPSGekxQN19MjgQ_1776789313 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , John Levon , Patrick Mooney , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 14/14] vfio-user: fix DMA write reply Date: Tue, 21 Apr 2026 18:34:38 +0200 Message-ID: <20260421163438.3447280-15-clg@redhat.com> In-Reply-To: <20260421163438.3447280-1-clg@redhat.com> References: <20260421163438.3447280-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.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.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, 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: 1776789437816154100 From: John Levon The protocol specifies that DMA write replies should include address+count, but the client code was only doing so for read. Fix that up. In addition, add a protocol clarification over how short writes may be reported in that reply. QEMU never reports a short write via the count field. Reported-by: Patrick Mooney Signed-off-by: John Levon Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20260410085716.877185-4-john.levon= @nutanix.com Signed-off-by: C=C3=A9dric Le Goater --- docs/interop/vfio-user.rst | 6 ++++++ hw/vfio-user/pci.c | 30 ++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/docs/interop/vfio-user.rst b/docs/interop/vfio-user.rst index d4766487ea6d0ee021316890d443814957cf6284..12deb25102af217f7f292b4cb65= 5dc4a6a92439a 100644 --- a/docs/interop/vfio-user.rst +++ b/docs/interop/vfio-user.rst @@ -1429,6 +1429,9 @@ Reply * *count* is the size of the data transferred. * *data* is the data read. =20 +Note that whether short reads return an error or just set count appropriat= ely is +a client-side choice; servers should be prepared to handle both cases. + ``VFIO_USER_DMA_WRITE`` ----------------------- =20 @@ -1469,6 +1472,9 @@ Reply * *address* is the client DMA memory address being accessed. * *count* is the size of the data transferred. =20 +Note that whether short writes return an error or just set count appropria= tely +is a client-side choice; servers should be prepared to handle both cases. + ``VFIO_USER_DEVICE_RESET`` -------------------------- =20 diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c index 64b8b3cb8cf5d66879af1703c4f2b5ae0c7418ca..facc79727acb82c35fec5b4bef7= 9e78b3878531a 100644 --- a/hw/vfio-user/pci.c +++ b/hw/vfio-user/pci.c @@ -109,6 +109,10 @@ static void vfio_user_dma_read(VFIOPCIDevice *vdev, VF= IOUserDMARW *msg) =20 r =3D pci_dma_read(pdev, res->offset, &res->data, res->count); =20 + /* + * pci_dma_read() doesn't support reporting short reads via the reply's + * count parameter; in this case, we'll reply with an error instead. + */ switch (r) { case MEMTX_OK: if (res->hdr.flags & VFIO_USER_NO_REPLY) { @@ -136,6 +140,7 @@ static void vfio_user_dma_write(VFIOPCIDevice *vdev, VF= IOUserDMARW *msg) { PCIDevice *pdev =3D PCI_DEVICE(vdev); VFIOUserProxy *proxy =3D vdev->vbasedev.proxy; + VFIOUserDMARW *res; MemTxResult r; =20 if (msg->hdr.size < sizeof(*msg)) { @@ -150,26 +155,35 @@ static void vfio_user_dma_write(VFIOPCIDevice *vdev, = VFIOUserDMARW *msg) =20 r =3D pci_dma_write(pdev, msg->offset, &msg->data, msg->count); =20 + res =3D g_malloc0(sizeof(*res)); + memcpy(res, msg, sizeof(*res)); + g_free(msg); + + /* + * pci_dma_write() doesn't support reporting short writes via the repl= y's + * count parameter; in this case, we'll reply with an error instead. + */ switch (r) { case MEMTX_OK: - if ((msg->hdr.flags & VFIO_USER_NO_REPLY) =3D=3D 0) { - vfio_user_send_reply(proxy, &msg->hdr, sizeof(msg->hdr)); - } else { - g_free(msg); + if (res->hdr.flags & VFIO_USER_NO_REPLY) { + g_free(res); + return; } + + vfio_user_send_reply(proxy, &res->hdr, sizeof(*res)); break; case MEMTX_ERROR: - vfio_user_send_error(proxy, &msg->hdr, EFAULT); + vfio_user_send_error(proxy, &res->hdr, EFAULT); break; case MEMTX_DECODE_ERROR: - vfio_user_send_error(proxy, &msg->hdr, ENODEV); + vfio_user_send_error(proxy, &res->hdr, ENODEV); break; case MEMTX_ACCESS_ERROR: - vfio_user_send_error(proxy, &msg->hdr, EPERM); + vfio_user_send_error(proxy, &res->hdr, EPERM); break; default: error_printf("vfio_user_dma_write unknown error %d\n", r); - vfio_user_send_error(vdev->vbasedev.proxy, &msg->hdr, EINVAL); + vfio_user_send_error(vdev->vbasedev.proxy, &res->hdr, EINVAL); } } =20 --=20 2.53.0