From nobody Sat Nov 15 16:07:32 2025 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=1749654645; cv=none; d=zohomail.com; s=zohoarc; b=KEcSGu2scG/hGKmzro2Xb2HuTzMQjTNOGfC9exHCxC4Z/oXM16yIm6uVGvqMtsoJPEGB7FEBve9oOr+hHt+LnkaAe7Cp+IefgwZc9h2nY7nTKfTWcp1sR3uGOeRKOAaL1CzxsjwYCmiXLlcYxrXB9FP3R3qdSoeRUVbYQUDmDZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654645; 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=3V1erp9IYlAc+EgRMbW4Q/hidSJSfzmi+tNxBKakHeY=; b=HLzztt62Zm+IH486Y0ciTWckFKoP50gRva7ppSnFN/KdMLPiZluF7L5/bfG+6Fu/AlVKS0N/71bzUTwAkzkPOO8gYoUmJIFyktyV4LKUtfpS9LvtkAaS3Oozw+m/yVhIQHfxU2OsE/MH7YCXM2qJnwDcP6PyrAK8KnUOcQQHzSY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654645188826.0779293406762; Wed, 11 Jun 2025 08:10:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2I-0004Og-Rj; Wed, 11 Jun 2025 11:06:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2D-0004MN-Pa for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:37 -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 1uPN2C-00072y-5v for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:37 -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-628-7A0dyRxjMjOgsxotjQ8GGQ-1; Wed, 11 Jun 2025 11:06:28 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 0F7811956095; Wed, 11 Jun 2025 15:06:27 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 21E8F18002B6; Wed, 11 Jun 2025 15:06:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654394; 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=3V1erp9IYlAc+EgRMbW4Q/hidSJSfzmi+tNxBKakHeY=; b=YLjNrOu0+VTeeDgviKdF0G/oBfvP09g+JeemVgHT12427/i2pL5Uwr+IaqJgtjRxyfzgno WfNsFrIz4dluiVFMBTF+MEnsZwYOvjJdMPb4SStMbhe8leyhpagChdGD+EHD3QKi59op+p T5S8QRcchguB6se17N9Q5bmtXAb+FLY= X-MC-Unique: 7A0dyRxjMjOgsxotjQ8GGQ-1 X-Mimecast-MFC-AGG-ID: 7A0dyRxjMjOgsxotjQ8GGQ_1749654387 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , John Levon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 01/27] vfio/container: Fix vfio_listener_commit() Date: Wed, 11 Jun 2025 17:05:53 +0200 Message-ID: <20250611150620.701903-2-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655215773116600 From: Zhenzhong Duan It's wrong to call into listener_begin callback in vfio_listener_commit(). Currently this impacts vfio-user. Fixes: d9b7d8b6993b ("vfio/container: pass listener_begin/commit callbacks") Signed-off-by: Zhenzhong Duan Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250609115433.401775-1-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/listener.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 203ed0314ec46225651a51d91df9c2e7c76168ed..735b5f21b7b87cff6b5e757f969= 6d9a7c1c44fbf 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -437,7 +437,7 @@ static void vfio_listener_commit(MemoryListener *listen= er) listener); void (*listener_commit)(VFIOContainerBase *bcontainer); =20 - listener_commit =3D VFIO_IOMMU_GET_CLASS(bcontainer)->listener_begin; + listener_commit =3D VFIO_IOMMU_GET_CLASS(bcontainer)->listener_commit; =20 if (listener_commit) { listener_commit(bcontainer); --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654538; cv=none; d=zohomail.com; s=zohoarc; b=VzMPDfkaMVKhBFwKfN00sLl6jRFodst/G6wl/GzZtpbpO4chMUF7EzX8rtcCw+948f1+Mpf4KkPK2UitSgjrJSNWGlv1Wg+cyYjkY76JaQvdvEJ6ZKO8ckogZVVHqDKWp+RIgykyF8uJ8g3eam3dp1VmYEOXxpk+reiqbxQt/0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654538; 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=IGUijn8OwNTfwcOPRbjli+qIh22n9IlcqzOHh08EtHM=; b=oBV9e87J3wQpMHtNFAVWER1ggi0Dave8+xFfeuPK6xHrlaH/n0WBLRl4yjc0+ekJhDE5CRgqBIZRke/qLeRG2E6/w6QndEnJsj9bVkgFQeNBpmZXBoC/ZmR8IBb8VlEMHArAAlRzP2wbjbTElbK0Y1jtM2FyUnbbEeBJpOwijEU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654538894800.8283958674712; Wed, 11 Jun 2025 08:08:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2I-0004Mm-J8; Wed, 11 Jun 2025 11:06:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2D-0004MB-8G for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:37 -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 1uPN2B-00072t-Dk for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:36 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-Z3gH8SuvMpaECHxrW8CRUw-1; Wed, 11 Jun 2025 11:06:31 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1072C19560B2; Wed, 11 Jun 2025 15:06:30 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8C7CC180045B; Wed, 11 Jun 2025 15:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654394; 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=IGUijn8OwNTfwcOPRbjli+qIh22n9IlcqzOHh08EtHM=; b=iXHGSx6P+JbhoYYH/PU5adQxOZSrUN1JJeM1lDz7wgwEd004Z7f8uawfJFPqkX8+EzBiGC AG5YvoxcL/py+NHUHo0Km+/2JsBq5ehEY2r+yUxPfAbQgTmT7iP6Nf3SD53rRSp7viFZxa WjQ5zv4UqKS/qvmQ5QuTk2S5Aku3mN0= X-MC-Unique: Z3gH8SuvMpaECHxrW8CRUw-1 X-Mimecast-MFC-AGG-ID: Z3gH8SuvMpaECHxrW8CRUw_1749654390 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , John Levon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Yi Liu Subject: [PULL 02/27] vfio/pci: Fix instance_size of VFIO_PCI_BASE Date: Wed, 11 Jun 2025 17:05:54 +0200 Message-ID: <20250611150620.701903-3-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655134440116600 From: Zhenzhong Duan Currently the final instance_size of VFIO_PCI_BASE is sizeof(PCIDevice). It should be sizeof(VFIOPCIDevice), VFIO_PCI uses same structure as base class VFIO_PCI_BASE, so no need to set its instance_size explicitly. This isn't catastrophic only because VFIO_PCI_BASE is an abstract class. Fixes: d4e392d0a99b ("vfio: add vfio-pci-base class") Signed-off-by: Zhenzhong Duan Reviewed-by: John Levon Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Yi Liu Link: https://lore.kernel.org/qemu-devel/20250611024228.423666-1-zhenzhong.= duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index b1250d85bf0124a22e3ba3859a47d2b176ade648..6748f4e876942f89138f9d8fedf= b99dab95b865e 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3425,7 +3425,7 @@ static void vfio_pci_base_dev_class_init(ObjectClass = *klass, const void *data) static const TypeInfo vfio_pci_base_dev_info =3D { .name =3D TYPE_VFIO_PCI_BASE, .parent =3D TYPE_PCI_DEVICE, - .instance_size =3D 0, + .instance_size =3D sizeof(VFIOPCIDevice), .abstract =3D true, .class_init =3D vfio_pci_base_dev_class_init, .interfaces =3D (const InterfaceInfo[]) { @@ -3647,7 +3647,6 @@ static void vfio_pci_dev_class_init(ObjectClass *klas= s, const void *data) static const TypeInfo vfio_pci_dev_info =3D { .name =3D TYPE_VFIO_PCI, .parent =3D TYPE_VFIO_PCI_BASE, - .instance_size =3D sizeof(VFIOPCIDevice), .class_init =3D vfio_pci_dev_class_init, .instance_init =3D vfio_instance_init, .instance_finalize =3D vfio_instance_finalize, --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654455; cv=none; d=zohomail.com; s=zohoarc; b=a+FyEjUP+3rNhlBLIp48k/AH76PtxRZcLX2EFYwHxwMwbmC1mkzhtKVXio8RZQZyotvoQy/RxXPeiFNaWQy2PJc3TXSEghbtjg054cRVa7559q+gesVwCxrev7kMIsjcO5LbTkyxxVQo7qaN7sZwdSAbNX1X+SHZ2QV6JHof+NA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654455; 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=yrPmCmOHXWBPEx6iXc7WMA0L48x/tM4Vkq6om4zAkgw=; b=ZjF+zGSvy3XhXXM8vVkbIulSmheTv8o1L8BUAMOxf61vaGr9TWq2ZMPg4/1YOaJlAFRkSPCy8Tk24xORsd8PW11voa/8lMhLz1YNPUFEoZup74yN6SfpxtCUV2pq2yiTfkoHWuelgNhwS8G0GVWbLKFih68IDGrrgagRz3bnmKA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654455294512.9812070551632; Wed, 11 Jun 2025 08:07:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2O-0004Qe-8J; Wed, 11 Jun 2025 11:06:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2F-0004Mg-B9 for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:40 -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 1uPN2D-00073r-KI for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:39 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-hlt_Pm7cPH6YjGqDI5HkFA-1; Wed, 11 Jun 2025 11:06:33 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 975001956056; Wed, 11 Jun 2025 15:06:32 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8D804180045B; Wed, 11 Jun 2025 15:06:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654396; 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=yrPmCmOHXWBPEx6iXc7WMA0L48x/tM4Vkq6om4zAkgw=; b=cxE6Ms4WeN9EBgpl78Io1b1VKF+Em6A+ILnyp4GI09Uh9LJ6PCq1rIeksqJ3qyrLFmBTOk OGx/ZbeM2tf6uLdCj8/GUBvgM8SMRgAaNcZC6dkT5RlFn2w0bFw6nBMZ85IgUQT63uz5fy fzB8T8TsJGOYIYkSuGlKAG3992I+juc= X-MC-Unique: hlt_Pm7cPH6YjGqDI5HkFA-1 X-Mimecast-MFC-AGG-ID: hlt_Pm7cPH6YjGqDI5HkFA_1749654392 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Rorie Reyes , Anthony Krowiak , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 03/27] hw/vfio/ap: notification handler for AP config changed event Date: Wed, 11 Jun 2025 17:05:55 +0200 Message-ID: <20250611150620.701903-4-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749654642265116600 From: Rorie Reyes Register an event notifier handler to process AP configuration change events by queuing the event and generating a CRW to let the guest know its AP configuration has changed Signed-off-by: Rorie Reyes Reviewed-by: Anthony Krowiak Link: https://lore.kernel.org/qemu-devel/20250609164418.17585-2-rreyes@linu= x.ibm.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/ap.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 785c0a019754a436c59357cf957c4dc6f81ba578..93c74ebedb937b7058b2c55a8b8= 5559be1d7c9ed 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -18,6 +18,7 @@ #include "hw/vfio/vfio-device.h" #include "system/iommufd.h" #include "hw/s390x/ap-device.h" +#include "hw/s390x/css.h" #include "qemu/error-report.h" #include "qemu/event_notifier.h" #include "qemu/main-loop.h" @@ -37,6 +38,7 @@ struct VFIOAPDevice { APDevice apdev; VFIODevice vdev; EventNotifier req_notifier; + EventNotifier cfg_notifier; }; =20 OBJECT_DECLARE_SIMPLE_TYPE(VFIOAPDevice, VFIO_AP_DEVICE) @@ -70,6 +72,18 @@ static void vfio_ap_req_notifier_handler(void *opaque) } } =20 +static void vfio_ap_cfg_chg_notifier_handler(void *opaque) +{ + VFIOAPDevice *vapdev =3D opaque; + + if (!event_notifier_test_and_clear(&vapdev->cfg_notifier)) { + return; + } + + css_generate_css_crws(0); + +} + static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev, unsigned int irq, Error **errp) { @@ -85,6 +99,10 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *= vapdev, notifier =3D &vapdev->req_notifier; fd_read =3D vfio_ap_req_notifier_handler; break; + case VFIO_AP_CFG_CHG_IRQ_INDEX: + notifier =3D &vapdev->cfg_notifier; + fd_read =3D vfio_ap_cfg_chg_notifier_handler; + break; default: error_setg(errp, "vfio: Unsupported device irq(%d)", irq); return false; @@ -137,6 +155,9 @@ static void vfio_ap_unregister_irq_notifier(VFIOAPDevic= e *vapdev, case VFIO_AP_REQ_IRQ_INDEX: notifier =3D &vapdev->req_notifier; break; + case VFIO_AP_CFG_CHG_IRQ_INDEX: + notifier =3D &vapdev->cfg_notifier; + break; default: error_report("vfio: Unsupported device irq(%d)", irq); return; @@ -176,6 +197,15 @@ static void vfio_ap_realize(DeviceState *dev, Error **= errp) warn_report_err(err); } =20 + if (!vfio_ap_register_irq_notifier(vapdev, VFIO_AP_CFG_CHG_IRQ_INDEX, = &err)) + { + /* + * Report this error, but do not make it a failing condition. + * Lack of this IRQ in the host does not prevent normal operation. + */ + warn_report_err(err); + } + return; =20 error: @@ -188,6 +218,7 @@ static void vfio_ap_unrealize(DeviceState *dev) VFIOAPDevice *vapdev =3D VFIO_AP_DEVICE(dev); =20 vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX); + vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_CFG_CHG_IRQ_INDEX); vfio_device_detach(&vapdev->vdev); g_free(vapdev->vdev.name); } --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654708; cv=none; d=zohomail.com; s=zohoarc; b=kC76Eihz7N2VLjbhsFl5NGcNvpt4Xhvkgzw1cKWNZxQxjI29NQ6WstnEnCa2KnkKj6txHIxFl5i+l4qm6rs7YcX5Mbk1N4ojcWwGPCB0AhAdOKp8nu6ikzECF3cMG5ZGeDodtbAV/Nxvw1Dw6GI18zlKqeAwAuFMkUe0j5zG5Zs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654708; 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=O0eT/RRLKkx75jgMhDk96Io1CaksG/gWiIfL1S0D1JI=; b=LCHZfvN9O4OmFG40y5rc5HCW3QIAV0pt6NGju1X3iDFNypb4g8VX24G+VEznO+5gTjN7898vmrufKQwNRZwp6KPfzfMTmX4LttX74gNTkIPeb4jMORGWS4o1lBQmZwVQBiEy5t3JC7DB3gt5eXHWK+gnzlHxXPwh3ghAof00hbk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654708071521.2269174138826; Wed, 11 Jun 2025 08:11:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2R-0004S6-PP; Wed, 11 Jun 2025 11:06:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2H-0004ON-MC for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:41 -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 1uPN2G-00074S-0j for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:41 -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-183-9eYkzUvsM9yuaHHDHAYnhg-1; Wed, 11 Jun 2025 11:06:37 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 0427B19560BD; Wed, 11 Jun 2025 15:06:35 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 209DB180045C; Wed, 11 Jun 2025 15:06:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654399; 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=O0eT/RRLKkx75jgMhDk96Io1CaksG/gWiIfL1S0D1JI=; b=ceF+dDAYZ/ToI7Evv5Kc7ZinXIBHQAr6ni2c7s0Dyah70wCR4fP07jcm81mWD+HsOLyopT WQNpOpIToEY/dx26+8wuRkkPRabVE8Npq9JtCjx70J1xCdGrJPebfqBE9YCcviTFinHcrV vpOeEYjDcmOm8fGY5y+ZJA5K88sWRXQ= X-MC-Unique: 9eYkzUvsM9yuaHHDHAYnhg-1 X-Mimecast-MFC-AGG-ID: 9eYkzUvsM9yuaHHDHAYnhg_1749654395 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Rorie Reyes , Anthony Krowiak , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 04/27] hw/vfio/ap: store object indicating AP config changed in a queue Date: Wed, 11 Jun 2025 17:05:56 +0200 Message-ID: <20250611150620.701903-5-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655262049116600 From: Rorie Reyes Creates an object indicating that an AP configuration change event has been received and stores it in a queue. These objects will later be used to store event information for an AP configuration change when the CHSC instruction is intercepted. Signed-off-by: Rorie Reyes Reviewed-by: Anthony Krowiak Link: https://lore.kernel.org/qemu-devel/20250609164418.17585-3-rreyes@linu= x.ibm.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/ap.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 93c74ebedb937b7058b2c55a8b85559be1d7c9ed..681fd4a4f1cb861cb287fca9ce2= 134e55ec20323 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -21,6 +21,7 @@ #include "hw/s390x/css.h" #include "qemu/error-report.h" #include "qemu/event_notifier.h" +#include "qemu/lockable.h" #include "qemu/main-loop.h" #include "qemu/module.h" #include "qemu/option.h" @@ -41,6 +42,15 @@ struct VFIOAPDevice { EventNotifier cfg_notifier; }; =20 +typedef struct APConfigChgEvent { + QTAILQ_ENTRY(APConfigChgEvent) next; +} APConfigChgEvent; + +static QTAILQ_HEAD(, APConfigChgEvent) cfg_chg_events =3D + QTAILQ_HEAD_INITIALIZER(cfg_chg_events); + +static QemuMutex cfg_chg_events_lock; + OBJECT_DECLARE_SIMPLE_TYPE(VFIOAPDevice, VFIO_AP_DEVICE) =20 static void vfio_ap_compute_needs_reset(VFIODevice *vdev) @@ -74,12 +84,19 @@ static void vfio_ap_req_notifier_handler(void *opaque) =20 static void vfio_ap_cfg_chg_notifier_handler(void *opaque) { + APConfigChgEvent *cfg_chg_event; VFIOAPDevice *vapdev =3D opaque; =20 if (!event_notifier_test_and_clear(&vapdev->cfg_notifier)) { return; } =20 + cfg_chg_event =3D g_new0(APConfigChgEvent, 1); + + WITH_QEMU_LOCK_GUARD(&cfg_chg_events_lock) { + QTAILQ_INSERT_TAIL(&cfg_chg_events, cfg_chg_event, next); + } + css_generate_css_crws(0); =20 } --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654452; cv=none; d=zohomail.com; s=zohoarc; b=MovPqxfbaJ+B3d0sA0PHoSoaLWgtjHMy/Z/ko+YSORdZnNZgbDf9Qlp4+iCqMouKSRIc4IOyJ3dyyUor1AOf5vgHPwI+a8aSC4cyAAfsowFy5fvD4DlZNyptydpsmHTm9xwj/ZssCrmyfaDQJeXkGQ4A5pca01++T80phMeeGrI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654452; 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=AW/pwmZORZx+McBlT7cscgzaAVx8u1KbpDgUZMs5o20=; b=beIkp60Gs0qCk1b4ie9Vk1XsEztXU9bK8FymV0LHtMrwGeTBqsEcpTpGGchM/D7ZQQdwsSCUtcHua/jAtKC4cwsOMD512Cb4I7UOLyJKef63LNfls1Sy9NXwXNwdFHqD5RRUNG4i3p5Ch930RUYrByQXJArTzHfqyNpd6mT/DQw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174965445283435.810384408690766; Wed, 11 Jun 2025 08:07:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2O-0004Qt-8j; Wed, 11 Jun 2025 11:06:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2K-0004Pd-G2 for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2I-00074s-LT for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:44 -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-128-b5Kr2RgOP8yfC_Za46Gg3w-1; Wed, 11 Jun 2025 11:06:38 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 63B4A19560A1; Wed, 11 Jun 2025 15:06:37 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 803AD180045C; Wed, 11 Jun 2025 15:06:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654401; 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=AW/pwmZORZx+McBlT7cscgzaAVx8u1KbpDgUZMs5o20=; b=gtNS4TLwXlc6ifU5FB3vGJ1X91pXlrZZSVA2cA20krJhrwJzMjgeM9GK6WQBqrHKS0l0eD wh1+KWcMdEFhSUVo7eBHZ1smF1tcFz4ejKBUgF5E18jnC4qYzlQN6Kd3M4Jnb52eFI3XKN Q4ZkRQMSKDC/t55Ez3MIItmhAK/+YJA= X-MC-Unique: b5Kr2RgOP8yfC_Za46Gg3w-1 X-Mimecast-MFC-AGG-ID: b5Kr2RgOP8yfC_Za46Gg3w_1749654397 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Rorie Reyes , Anthony Krowiak , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 05/27] hw/vfio/ap: Storing event information for an AP configuration change event Date: Wed, 11 Jun 2025 17:05:57 +0200 Message-ID: <20250611150620.701903-6-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749654609220116600 From: Rorie Reyes These functions can be invoked by the function that handles interception of the CHSC SEI instruction for requests indicating the accessibility of one or more adjunct processors has changed. Signed-off-by: Rorie Reyes Reviewed-by: Anthony Krowiak Link: https://lore.kernel.org/qemu-devel/20250609164418.17585-4-rreyes@linu= x.ibm.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/s390x/ap-bridge.h | 39 +++++++++++++++++++++++++++++++++++ hw/vfio/ap.c | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/include/hw/s390x/ap-bridge.h b/include/hw/s390x/ap-bridge.h index 470e439a98ed5306dadb29f7507ca880756eb13f..7efc52928db15c429b2486e09e7= 01b5cc4a799f2 100644 --- a/include/hw/s390x/ap-bridge.h +++ b/include/hw/s390x/ap-bridge.h @@ -16,4 +16,43 @@ =20 void s390_init_ap(void); =20 +typedef struct ChscSeiNt0Res { + uint16_t length; + uint16_t code; + uint8_t reserved1; + uint16_t reserved2; + uint8_t nt; +#define PENDING_EVENT_INFO_BITMASK 0x80; + uint8_t flags; + uint8_t reserved3; + uint8_t rs; + uint8_t cc; +} QEMU_PACKED ChscSeiNt0Res; + +#define NT0_RES_RESPONSE_CODE 1 +#define NT0_RES_NT_DEFAULT 0 +#define NT0_RES_RS_AP_CHANGE 5 +#define NT0_RES_CC_AP_CHANGE 3 + +#define EVENT_INFORMATION_NOT_STORED 1 +#define EVENT_INFORMATION_STORED 0 + +/** + * ap_chsc_sei_nt0_get_event - Retrieve the next pending AP config + * change event + * @res: Pointer to a ChscSeiNt0Res struct to be filled with event + * data + * + * This function checks for any pending AP config change events and, + * if present, populates the provided response structure with the + * appropriate SEI NT0 fields. + * + * Return: + * EVENT_INFORMATION_STORED - An event was available and written to @res + * EVENT_INFORMATION_NOT_STORED - No event was available + */ +int ap_chsc_sei_nt0_get_event(void *res); + +bool ap_chsc_sei_nt0_have_event(void); + #endif diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 681fd4a4f1cb861cb287fca9ce2134e55ec20323..874e0d1eaf1dafa105f9f42705e= 9973ffc719803 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -10,6 +10,7 @@ * directory. */ =20 +#include #include "qemu/osdep.h" #include CONFIG_DEVICES /* CONFIG_IOMMUFD */ #include @@ -101,6 +102,38 @@ static void vfio_ap_cfg_chg_notifier_handler(void *opa= que) =20 } =20 +int ap_chsc_sei_nt0_get_event(void *res) +{ + ChscSeiNt0Res *nt0_res =3D (ChscSeiNt0Res *)res; + APConfigChgEvent *cfg_chg_event; + + WITH_QEMU_LOCK_GUARD(&cfg_chg_events_lock) { + if (QTAILQ_EMPTY(&cfg_chg_events)) { + return EVENT_INFORMATION_NOT_STORED; + } + + cfg_chg_event =3D QTAILQ_FIRST(&cfg_chg_events); + QTAILQ_REMOVE(&cfg_chg_events, cfg_chg_event, next); + } + + memset(nt0_res, 0, sizeof(*nt0_res)); + g_free(cfg_chg_event); + nt0_res->flags |=3D PENDING_EVENT_INFO_BITMASK; + nt0_res->length =3D sizeof(ChscSeiNt0Res); + nt0_res->code =3D NT0_RES_RESPONSE_CODE; + nt0_res->nt =3D NT0_RES_NT_DEFAULT; + nt0_res->rs =3D NT0_RES_RS_AP_CHANGE; + nt0_res->cc =3D NT0_RES_CC_AP_CHANGE; + + return EVENT_INFORMATION_STORED; +} + +bool ap_chsc_sei_nt0_have_event(void) +{ + QEMU_LOCK_GUARD(&cfg_chg_events_lock); + return !QTAILQ_EMPTY(&cfg_chg_events); +} + static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev, unsigned int irq, Error **errp) { @@ -197,6 +230,13 @@ static void vfio_ap_realize(DeviceState *dev, Error **= errp) VFIOAPDevice *vapdev =3D VFIO_AP_DEVICE(dev); VFIODevice *vbasedev =3D &vapdev->vdev; =20 + static bool lock_initialized; + + if (!lock_initialized) { + qemu_mutex_init(&cfg_chg_events_lock); + lock_initialized =3D true; + } + if (!vfio_device_get_name(vbasedev, errp)) { return; } --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654652; cv=none; d=zohomail.com; s=zohoarc; b=ADp1dr1gKlFri73kX5UE6OTEE1XzCd30LZUDtX2LOWok8miMCILJKGi2EfpQBkSqt3mWij/QInrRyr3NB6r/CwVEMB+HIlKBSG8lVfMfz8wIcPKLqyRQBWAtcciTM4AG9PZOcReslb9KsLT+sakuAtR8Xped9X+ocm4hO7szUV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654652; 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=v+Z6bEAFtbPbilkZ0EIqHvHGBwZUqeGe9jszTIGujG4=; b=eMjeVgowt08xvBp67jkd5K4908Nd60+ujm/Cjm1JlQlW3PLFGTnr9UtxA3OUKQYbRupVq6ykZ+jP2OckznwYniFZwedPDCjcRGhuHPRaOxL1LaSoaJO42OSha9pTpyMrBcOM0/jaG+/DsN1BW4mE92X8qmbSnGhJ+wE6oOdiueY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654652584967.744178058723; Wed, 11 Jun 2025 08:10:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2V-0004TH-BF; Wed, 11 Jun 2025 11:06:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2M-0004Qu-BS for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:47 -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 1uPN2K-000753-DM for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:46 -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-527-4460fcEyM46f_1rZVVUDUA-1; Wed, 11 Jun 2025 11:06:41 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 607DA1955F44; Wed, 11 Jun 2025 15:06:40 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 05A8718002B6; Wed, 11 Jun 2025 15:06:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654403; 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=v+Z6bEAFtbPbilkZ0EIqHvHGBwZUqeGe9jszTIGujG4=; b=PsGgD16HkB1BP3H5569ooBUxESyjWLoEmG7sf2fBURtGxGq4oH5yVDFtPYpB0dhvQ1/hHf LX/jldqGgg1H7zSMbj38eIIgunHQnkDy90DjxnlRCdUhF1J7mcdNIvDPCN2Nw8UAp5IiAb EcSeSTOhRsOR8D5Gr5YK8dokU7CgsCQ= X-MC-Unique: 4460fcEyM46f_1rZVVUDUA-1 X-Mimecast-MFC-AGG-ID: 4460fcEyM46f_1rZVVUDUA_1749654400 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Rorie Reyes , Anthony Krowiak , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 06/27] s390: implementing CHSC SEI for AP config change Date: Wed, 11 Jun 2025 17:05:58 +0200 Message-ID: <20250611150620.701903-7-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655224643116600 From: Rorie Reyes Handle interception of the CHSC SEI instruction for requests indicating the guest's AP configuration has changed. If configuring --without-default-devices, hw/s390x/ap-stub.c was created to handle such circumstance. Also added the following to hw/s390x/meson.build if CONFIG_VFIO_AP is false, it will use the stub file. Signed-off-by: Rorie Reyes Reviewed-by: Anthony Krowiak Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250609164418.17585-5-rreyes@linu= x.ibm.com Signed-off-by: C=C3=A9dric Le Goater --- MAINTAINERS | 1 + hw/s390x/ap-stub.c | 21 +++++++++++++++++++++ target/s390x/ioinst.c | 11 +++++++++-- hw/s390x/meson.build | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 hw/s390x/ap-stub.c diff --git a/MAINTAINERS b/MAINTAINERS index aa6763077ea87af0d527319f1cb13e4468b1f299..1e84bfeaeec7f9e5cecb7dd083a= ff52bc61fe884 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -112,6 +112,7 @@ F: hw/intc/s390_flic.c F: hw/intc/s390_flic_kvm.c F: hw/s390x/ F: hw/vfio/ap.c +F: hw/s390x/ap-stub.c F: hw/vfio/ccw.c F: hw/watchdog/wdt_diag288.c F: include/hw/s390x/ diff --git a/hw/s390x/ap-stub.c b/hw/s390x/ap-stub.c new file mode 100644 index 0000000000000000000000000000000000000000..001fe5f8b015e05e6e06a9c3797= d54d6718f7716 --- /dev/null +++ b/hw/s390x/ap-stub.c @@ -0,0 +1,21 @@ +/* + * VFIO based AP matrix device assignment + * + * Copyright 2025 IBM Corp. + * Author(s): Rorie Reyes + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/s390x/ap-bridge.h" + +int ap_chsc_sei_nt0_get_event(void *res) +{ + return EVENT_INFORMATION_NOT_STORED; +} + +bool ap_chsc_sei_nt0_have_event(void) +{ + return false; +} diff --git a/target/s390x/ioinst.c b/target/s390x/ioinst.c index fe62ba5b06bd8a92101ee8ed010a5fc655c26223..2320dd4c1224e6e4a9396e23f06= cc7cf4ffb358d 100644 --- a/target/s390x/ioinst.c +++ b/target/s390x/ioinst.c @@ -18,6 +18,7 @@ #include "trace.h" #include "hw/s390x/s390-pci-bus.h" #include "target/s390x/kvm/pv.h" +#include "hw/s390x/ap-bridge.h" =20 /* All I/O instructions but chsc use the s format */ static uint64_t get_address_from_regs(CPUS390XState *env, uint32_t ipb, @@ -574,13 +575,19 @@ out: =20 static int chsc_sei_nt0_get_event(void *res) { - /* no events yet */ + if (s390_has_feat(S390_FEAT_AP)) { + return ap_chsc_sei_nt0_get_event(res); + } + return 1; } =20 static int chsc_sei_nt0_have_event(void) { - /* no events yet */ + if (s390_has_feat(S390_FEAT_AP)) { + return ap_chsc_sei_nt0_have_event(); + } + return 0; } =20 diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index 3bbebfd817dfaadd55ee8d669be000aee8d5d517..99cbcbd7d633c1379be484d01f2= 96f7c7c7b8a2f 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -33,6 +33,7 @@ s390x_ss.add(when: 'CONFIG_S390_CCW_VIRTIO', if_true: fil= es( )) s390x_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('3270-ccw.c')) s390x_ss.add(when: 'CONFIG_VFIO', if_true: files('s390-pci-vfio.c')) +s390x_ss.add(when: 'CONFIG_VFIO_AP', if_false: files('ap-stub.c')) =20 virtio_ss =3D ss.source_set() virtio_ss.add(files('virtio-ccw.c')) --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654753; cv=none; d=zohomail.com; s=zohoarc; b=NlCuyTw3iA/cZGyx82GOq2hOFbF8wqKuOyxCmLwEO4hrqJ2pBngog0TOIA2tXov5vDiyGlWnnAT2K/pompgNB6UeDKWuSCQHeXB/aLzgdxiImpBxmq79IzzS0bYTSS5i2f6r81drq4G5d9Jt7zQckwgOcLe4Lwbbi2NVvTJ5oR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654753; 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=+VU1TB5grpCeBAJ9Vl8LSO6PsVx0nbNU2xZlFwjklSA=; b=QyKvjHdymUN9R0B9gB5jFXRAxyj3aD5d61XPm5xL5US3pOiUejmCbVa+YR1jFof3Y4GMwBTGL1LaUZCCDfs6uuniFpUOiA0mnUsS6KV0+3Omk535Erk4IXq2npZYwWeqxaUUpE2d8aCrPH1L4ckRMVy6dVgFPFPvlbHBaLS4zE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654753089652.8330778777979; Wed, 11 Jun 2025 08:12:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2X-0004U5-CO; Wed, 11 Jun 2025 11:06:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2P-0004Rb-KZ for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:49 -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 1uPN2M-00075d-SN for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:48 -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-654-ntgBjuHNMmGo3gaxaT96TA-1; Wed, 11 Jun 2025 11:06:43 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 C36B919560BA; Wed, 11 Jun 2025 15:06:42 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DDC4C180045B; Wed, 11 Jun 2025 15:06:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654406; 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=+VU1TB5grpCeBAJ9Vl8LSO6PsVx0nbNU2xZlFwjklSA=; b=e0olNFrqmdOPfi96Gzsgi27VucuAcFnfxzDarWVskGf74n5ggB+S80nkbcX5W5bd+BHWtC LD1k/dXpR31BLVeivIZ8sMIT2yYkklklfjf4G74tD1wcyIeGU45mhqaGjNuClj2K306fuR 6HRxGfFce1HYXAU932vgNtrhGGSx9PA= X-MC-Unique: ntgBjuHNMmGo3gaxaT96TA-1 X-Mimecast-MFC-AGG-ID: ntgBjuHNMmGo3gaxaT96TA_1749654402 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , John Levon , Mark Cave-Ayland , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 07/27] vfio: export PCI helpers needed for vfio-user Date: Wed, 11 Jun 2025 17:05:59 +0200 Message-ID: <20250611150620.701903-8-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655271268116600 From: John Levon The vfio-user code will need to re-use various parts of the vfio PCI code. Export them in hw/vfio/pci.h, and rename them to the vfio_pci_* namespace. Signed-off-by: John Levon Reviewed-by: Mark Cave-Ayland Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250607001056.335310-2-john.levon= @nutanix.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 11 ++++++++++ hw/vfio/pci.c | 48 ++++++++++++++++++++++---------------------- hw/vfio/trace-events | 6 +++--- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 5ce0fb916f3896a448b59fc0b99e892c11c3a9e1..d4c6b2e7b77f26e44f902e6b840= d7e39d39de3e9 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -248,4 +248,15 @@ void vfio_display_finalize(VFIOPCIDevice *vdev); =20 extern const VMStateDescription vfio_display_vmstate; =20 +void vfio_pci_bars_exit(VFIOPCIDevice *vdev); +bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp); +bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp); +bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp); +void vfio_pci_intx_eoi(VFIODevice *vbasedev); +void vfio_pci_put_device(VFIOPCIDevice *vdev); +bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp); +void vfio_pci_register_err_notifier(VFIOPCIDevice *vdev); +void vfio_pci_register_req_notifier(VFIOPCIDevice *vdev); +void vfio_pci_teardown_msi(VFIOPCIDevice *vdev); + #endif /* HW_VFIO_VFIO_PCI_H */ diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 6748f4e876942f89138f9d8fedfb99dab95b865e..2901cedf6f3e4e1283cb59a1ff6= c8ddb99a41b56 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -103,7 +103,7 @@ static void vfio_intx_interrupt(void *opaque) } } =20 -static void vfio_intx_eoi(VFIODevice *vbasedev) +void vfio_pci_intx_eoi(VFIODevice *vbasedev) { VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); =20 @@ -111,7 +111,7 @@ static void vfio_intx_eoi(VFIODevice *vbasedev) return; } =20 - trace_vfio_intx_eoi(vbasedev->name); + trace_vfio_pci_intx_eoi(vbasedev->name); =20 vdev->intx.pending =3D false; pci_irq_deassert(&vdev->pdev); @@ -236,7 +236,7 @@ static void vfio_intx_update(VFIOPCIDevice *vdev, PCIIN= TxRoute *route) } =20 /* Re-enable the interrupt in cased we missed an EOI */ - vfio_intx_eoi(&vdev->vbasedev); + vfio_pci_intx_eoi(&vdev->vbasedev); } =20 static void vfio_intx_routing_notifier(PCIDevice *pdev) @@ -1743,7 +1743,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int = pos, Error **errp) return true; } =20 -static void vfio_teardown_msi(VFIOPCIDevice *vdev) +void vfio_pci_teardown_msi(VFIOPCIDevice *vdev) { msi_uninit(&vdev->pdev); =20 @@ -1839,7 +1839,7 @@ static void vfio_bars_register(VFIOPCIDevice *vdev) } } =20 -static void vfio_bars_exit(VFIOPCIDevice *vdev) +void vfio_pci_bars_exit(VFIOPCIDevice *vdev) { int i; =20 @@ -2430,7 +2430,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev) g_free(config); } =20 -static bool vfio_add_capabilities(VFIOPCIDevice *vdev, Error **errp) +bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; =20 @@ -2706,7 +2706,7 @@ static int vfio_pci_load_config(VFIODevice *vbasedev,= QEMUFile *f) static VFIODeviceOps vfio_pci_ops =3D { .vfio_compute_needs_reset =3D vfio_pci_compute_needs_reset, .vfio_hot_reset_multi =3D vfio_pci_hot_reset_multi, - .vfio_eoi =3D vfio_intx_eoi, + .vfio_eoi =3D vfio_pci_intx_eoi, .vfio_get_object =3D vfio_pci_get_object, .vfio_save_config =3D vfio_pci_save_config, .vfio_load_config =3D vfio_pci_load_config, @@ -2777,7 +2777,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **e= rrp) return true; } =20 -static bool vfio_populate_device(VFIOPCIDevice *vdev, Error **errp) +bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp) { VFIODevice *vbasedev =3D &vdev->vbasedev; struct vfio_region_info *reg_info =3D NULL; @@ -2823,7 +2823,7 @@ static bool vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) return false; } =20 - trace_vfio_populate_device_config(vdev->vbasedev.name, + trace_vfio_pci_populate_device_config(vdev->vbasedev.name, (unsigned long)reg_info->size, (unsigned long)reg_info->offset, (unsigned long)reg_info->flags); @@ -2845,7 +2845,7 @@ static bool vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) ret =3D vfio_device_get_irq_info(vbasedev, VFIO_PCI_ERR_IRQ_INDEX, &ir= q_info); if (ret) { /* This can fail for an old kernel or legacy PCI dev */ - trace_vfio_populate_device_get_irq_info_failure(strerror(-ret)); + trace_vfio_pci_populate_device_get_irq_info_failure(strerror(-ret)= ); } else if (irq_info.count =3D=3D 1) { vdev->pci_aer =3D true; } else { @@ -2857,7 +2857,7 @@ static bool vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) return true; } =20 -static void vfio_pci_put_device(VFIOPCIDevice *vdev) +void vfio_pci_put_device(VFIOPCIDevice *vdev) { vfio_display_finalize(vdev); vfio_bars_finalize(vdev); @@ -2905,7 +2905,7 @@ static void vfio_err_notifier_handler(void *opaque) * and continue after disabling error recovery support for the * device. */ -static void vfio_register_err_notifier(VFIOPCIDevice *vdev) +void vfio_pci_register_err_notifier(VFIOPCIDevice *vdev) { Error *err =3D NULL; int32_t fd; @@ -2964,7 +2964,7 @@ static void vfio_req_notifier_handler(void *opaque) } } =20 -static void vfio_register_req_notifier(VFIOPCIDevice *vdev) +void vfio_pci_register_req_notifier(VFIOPCIDevice *vdev) { struct vfio_irq_info irq_info; Error *err =3D NULL; @@ -3018,7 +3018,7 @@ static void vfio_unregister_req_notifier(VFIOPCIDevic= e *vdev) vdev->req_enabled =3D false; } =20 -static bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp) +bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; VFIODevice *vbasedev =3D &vdev->vbasedev; @@ -3124,7 +3124,7 @@ static bool vfio_pci_config_setup(VFIOPCIDevice *vdev= , Error **errp) return true; } =20 -static bool vfio_interrupt_setup(VFIOPCIDevice *vdev, Error **errp) +bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; =20 @@ -3214,7 +3214,7 @@ static void vfio_pci_realize(PCIDevice *pdev, Error *= *errp) goto error; } =20 - if (!vfio_populate_device(vdev, errp)) { + if (!vfio_pci_populate_device(vdev, errp)) { goto error; } =20 @@ -3228,7 +3228,7 @@ static void vfio_pci_realize(PCIDevice *pdev, Error *= *errp) goto out_teardown; } =20 - if (!vfio_add_capabilities(vdev, errp)) { + if (!vfio_pci_add_capabilities(vdev, errp)) { goto out_unset_idev; } =20 @@ -3244,7 +3244,7 @@ static void vfio_pci_realize(PCIDevice *pdev, Error *= *errp) vfio_bar_quirk_setup(vdev, i); } =20 - if (!vfio_interrupt_setup(vdev, errp)) { + if (!vfio_pci_interrupt_setup(vdev, errp)) { goto out_unset_idev; } =20 @@ -3288,8 +3288,8 @@ static void vfio_pci_realize(PCIDevice *pdev, Error *= *errp) } } =20 - vfio_register_err_notifier(vdev); - vfio_register_req_notifier(vdev); + vfio_pci_register_err_notifier(vdev); + vfio_pci_register_req_notifier(vdev); vfio_setup_resetfn_quirk(vdev); =20 return; @@ -3310,8 +3310,8 @@ out_unset_idev: pci_device_unset_iommu_device(pdev); } out_teardown: - vfio_teardown_msi(vdev); - vfio_bars_exit(vdev); + vfio_pci_teardown_msi(vdev); + vfio_pci_bars_exit(vdev); error: error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->name); } @@ -3338,9 +3338,9 @@ static void vfio_exitfn(PCIDevice *pdev) if (vdev->intx.mmap_timer) { timer_free(vdev->intx.mmap_timer); } - vfio_teardown_msi(vdev); + vfio_pci_teardown_msi(vdev); vfio_pci_disable_rp_atomics(vdev); - vfio_bars_exit(vdev); + vfio_pci_bars_exit(vdev); vfio_migration_exit(vbasedev); if (!vbasedev->mdev) { pci_device_unset_iommu_device(pdev); diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index e90ec9bff8d5fa51afde7b55fb736a8d51fef1b0..f06236f37b72cc64868456be3a5= a58fdb5beb829 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -2,7 +2,7 @@ =20 # pci.c vfio_intx_interrupt(const char *name, char line) " (%s) Pin %c" -vfio_intx_eoi(const char *name) " (%s) EOI" +vfio_pci_intx_eoi(const char *name) " (%s) EOI" vfio_intx_enable_kvm(const char *name) " (%s) KVM INTx accel enabled" vfio_intx_disable_kvm(const char *name) " (%s) KVM INTx accel disabled" vfio_intx_update(const char *name, int new_irq, int target_irq) " (%s) IRQ= moved %d -> %d" @@ -35,8 +35,8 @@ vfio_pci_hot_reset(const char *name, const char *type) " = (%s) %s" vfio_pci_hot_reset_has_dep_devices(const char *name) "%s: hot reset depend= ent devices:" vfio_pci_hot_reset_dep_devices(int domain, int bus, int slot, int function= , int group_id) "\t%04x:%02x:%02x.%x group %d" vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot re= set: %s" -vfio_populate_device_config(const char *name, unsigned long size, unsigned= long offset, unsigned long flags) "Device '%s' config: size: 0x%lx, offset= : 0x%lx, flags: 0x%lx" -vfio_populate_device_get_irq_info_failure(const char *errstr) "VFIO_DEVICE= _GET_IRQ_INFO failure: %s" +vfio_pci_populate_device_config(const char *name, unsigned long size, unsi= gned long offset, unsigned long flags) "Device '%s' config: size: 0x%lx, of= fset: 0x%lx, flags: 0x%lx" +vfio_pci_populate_device_get_irq_info_failure(const char *errstr) "VFIO_DE= VICE_GET_IRQ_INFO failure: %s" vfio_mdev(const char *name, bool is_mdev) " (%s) is_mdev %d" vfio_add_ext_cap_dropped(const char *name, uint16_t cap, uint16_t offset) = "%s 0x%x@0x%x" vfio_pci_reset(const char *name) " (%s)" --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654553; cv=none; d=zohomail.com; s=zohoarc; b=WxH7uvwUw/aE+HHMlw3klKYZscxT4PBxRj8Q1Qxis1wIdckDZ7qKnjMiye2m+Ny+cQ53V6YEDCZgcFBpe0sr9GNJs7hk6yyKi7SK1Hg2x6iGv5Jsh4SSlRljKrGLp9CUb9GFozXKDGUcMJyH92a5Z5B541nCjbRzVwJOhsn0AKc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654553; 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=MUGT0dF9kElz2HxdD/WmTDEZEkfwDZyixh8VsmslCw8=; b=na1fbyprnbbP7Pd0ZciJhjke/9n/mNo4xbC53ejrrM50bO/HZsj/5eF5Y+lBhddF6wMvmz4m8gAcx5/Ztavxz8mM/dBO2NY6fL3WGfEfz+OZd6iuoM+LTpe5Kw7u5StWQ1NevCRmcarfwMLMr9RcxcsJl6QWaw0R0x4IXNH098c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654553367657.3443562098547; Wed, 11 Jun 2025 08:09:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2a-0004Vb-3U; Wed, 11 Jun 2025 11:07:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2T-0004Sj-9a for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:54 -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 1uPN2R-00076P-9C for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:53 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-660-FblJkeDENpS7nJjZ5via5A-1; Wed, 11 Jun 2025 11:06:45 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0B750195608B; Wed, 11 Jun 2025 15:06:45 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4A0CC180045C; Wed, 11 Jun 2025 15:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654409; 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=MUGT0dF9kElz2HxdD/WmTDEZEkfwDZyixh8VsmslCw8=; b=VbFE09E6e1N3BB2acuTVA/mIbsEO3mPVzr7hdZSQRlG03/F0sGMGnqiXm81TWmupOMpJx5 UqMpU4F0gKLSERdWmqPsySTsOGfqty4E1WBx0MX37JpnFKxKTYtBlNTxItqymYP5jBJhpj blFdjHoRU78fXl5n6l/qo+4si8fTkYI= X-MC-Unique: FblJkeDENpS7nJjZ5via5A-1 X-Mimecast-MFC-AGG-ID: FblJkeDENpS7nJjZ5via5A_1749654405 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 08/27] vfio: add per-region fd support Date: Wed, 11 Jun 2025 17:06:00 +0200 Message-ID: <20250611150620.701903-9-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655165632116600 From: John Levon For vfio-user, each region has its own fd rather than sharing vbasedev's. Add the necessary plumbing to support this, and use the correct fd in vfio_region_mmap(). Signed-off-by: John Levon Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250607001056.335310-4-john.levon= @nutanix.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-device.h | 7 +++++-- hw/vfio/device.c | 29 +++++++++++++++++++++++++---- hw/vfio/region.c | 9 +++++++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 8bcb3c19f62b5a47c835e10149c04a9bd7536520..bf54fc69205a713263a666b480b= 2399e2a91f552 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -66,6 +66,7 @@ typedef struct VFIODevice { OnOffAuto enable_migration; OnOffAuto migration_multifd_transfer; bool migration_events; + bool use_region_fds; VFIODeviceOps *ops; VFIODeviceIOOps *io_ops; unsigned int num_irqs; @@ -84,6 +85,7 @@ typedef struct VFIODevice { VFIOIOASHwpt *hwpt; QLIST_ENTRY(VFIODevice) hwpt_next; struct vfio_region_info **reginfo; + int *region_fds; } VFIODevice; =20 struct VFIODeviceOps { @@ -170,10 +172,11 @@ struct VFIODeviceIOOps { /** * @get_region_info * - * Fill in @info with information on the region given by @info->index. + * Fill in @info (and optionally @fd) with information on the region g= iven + * by @info->index. */ int (*get_region_info)(VFIODevice *vdev, - struct vfio_region_info *info); + struct vfio_region_info *info, int *fd); =20 /** * @get_irq_info diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 9fba2c7272f207f2fe870fc97b46c342bd57dc0a..a4bdde8e8bd49c82923d0d29a44= f18fd71a44204 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -200,6 +200,7 @@ int vfio_device_get_region_info(VFIODevice *vbasedev, i= nt index, struct vfio_region_info **info) { size_t argsz =3D sizeof(struct vfio_region_info); + int fd =3D -1; int ret; =20 /* check cache */ @@ -214,7 +215,7 @@ int vfio_device_get_region_info(VFIODevice *vbasedev, i= nt index, retry: (*info)->argsz =3D argsz; =20 - ret =3D vbasedev->io_ops->get_region_info(vbasedev, *info); + ret =3D vbasedev->io_ops->get_region_info(vbasedev, *info, &fd); if (ret !=3D 0) { g_free(*info); *info =3D NULL; @@ -225,11 +226,19 @@ retry: argsz =3D (*info)->argsz; *info =3D g_realloc(*info, argsz); =20 + if (fd !=3D -1) { + close(fd); + fd =3D -1; + } + goto retry; } =20 /* fill cache */ vbasedev->reginfo[index] =3D *info; + if (vbasedev->region_fds !=3D NULL) { + vbasedev->region_fds[index] =3D fd; + } =20 return 0; } @@ -334,6 +343,7 @@ void vfio_device_init(VFIODevice *vbasedev, int type, V= FIODeviceOps *ops, vbasedev->io_ops =3D &vfio_device_io_ops_ioctl; vbasedev->dev =3D dev; vbasedev->fd =3D -1; + vbasedev->use_region_fds =3D false; =20 vbasedev->ram_block_discard_allowed =3D ram_discard; } @@ -444,6 +454,9 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOCont= ainerBase *bcontainer, =20 vbasedev->reginfo =3D g_new0(struct vfio_region_info *, vbasedev->num_regions); + if (vbasedev->use_region_fds) { + vbasedev->region_fds =3D g_new0(int, vbasedev->num_regions); + } } =20 void vfio_device_unprepare(VFIODevice *vbasedev) @@ -452,9 +465,14 @@ void vfio_device_unprepare(VFIODevice *vbasedev) =20 for (i =3D 0; i < vbasedev->num_regions; i++) { g_free(vbasedev->reginfo[i]); + if (vbasedev->region_fds !=3D NULL && vbasedev->region_fds[i] !=3D= -1) { + close(vbasedev->region_fds[i]); + } + } - g_free(vbasedev->reginfo); - vbasedev->reginfo =3D NULL; + + g_clear_pointer(&vbasedev->reginfo, g_free); + g_clear_pointer(&vbasedev->region_fds, g_free); =20 QLIST_REMOVE(vbasedev, container_next); QLIST_REMOVE(vbasedev, global_next); @@ -476,10 +494,13 @@ static int vfio_device_io_device_feature(VFIODevice *= vbasedev, } =20 static int vfio_device_io_get_region_info(VFIODevice *vbasedev, - struct vfio_region_info *info) + struct vfio_region_info *info, + int *fd) { int ret; =20 + *fd =3D -1; + ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_GET_REGION_INFO, info); =20 return ret < 0 ? -errno : ret; diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 34752c3f65c4b43fc961754657b18f5269c01ef1..cb172f2136dab7d5e649e588bda= 16b0e4821079d 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -241,6 +241,7 @@ int vfio_region_mmap(VFIORegion *region) { int i, ret, prot =3D 0; char *name; + int fd; =20 if (!region->mem) { return 0; @@ -271,14 +272,18 @@ int vfio_region_mmap(VFIORegion *region) goto no_mmap; } =20 + /* Use the per-region fd if set, or the shared fd. */ + fd =3D region->vbasedev->region_fds ? + region->vbasedev->region_fds[region->nr] : + region->vbasedev->fd, + map_align =3D (void *)ROUND_UP((uintptr_t)map_base, (uintptr_t)ali= gn); munmap(map_base, map_align - map_base); munmap(map_align + region->mmaps[i].size, align - (map_align - map_base)); =20 region->mmaps[i].mmap =3D mmap(map_align, region->mmaps[i].size, p= rot, - MAP_SHARED | MAP_FIXED, - region->vbasedev->fd, + MAP_SHARED | MAP_FIXED, fd, region->fd_offset + region->mmaps[i].offset); if (region->mmaps[i].mmap =3D=3D MAP_FAILED) { --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654567; cv=none; d=zohomail.com; s=zohoarc; b=GFWIijmX6I6WaytR4w5SeVTcbga/KcRwBfbFmsPuGbpL1JD7VYcJSvon3V12aFZ/9gDWYhyD8Tf6xT3KjZnNuiSCE6Dw8y3GiChB3dmfcxhbNvGScjwXvtDkhqTRcRqF7k/l7wXATBGFKywTd+efNl180P+Efk5G71aBBccLomM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654567; 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=TLHEBL9BNaXvqHw39biK7DZfHGB227mG2Q5arGi0+/8=; b=KO+Ob8ymsW/uMsJk+XDhMYmp+65AlPWauFQ2tM/bI4uEiQajEPF//vxwjlTeIh4hdJzyP9rdx/4lpL8ojyrZxJD8OlowbpUSYkmcX8oWZFgkBqmlSFfb6yQcoyX5hOAmjrVRIor/WRxAM7mBoOQ+ioTeGCtzJN2yDk/9XxIJvDU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654566794132.78239351187915; Wed, 11 Jun 2025 08:09:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2W-0004TJ-6X; Wed, 11 Jun 2025 11:06:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2T-0004St-K3 for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2R-00076d-TA for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:53 -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-269-uhvcrUSgN62LsAPCqw7NYA-1; Wed, 11 Jun 2025 11:06:49 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 1E9C3195608E; Wed, 11 Jun 2025 15:06:48 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 87A16180045B; Wed, 11 Jun 2025 15:06:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654411; 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=TLHEBL9BNaXvqHw39biK7DZfHGB227mG2Q5arGi0+/8=; b=deazTqnewX1RwsN4DiRGsKbGvL43sSqmtTMrYv2n6sk257UY4xMmu7EuoK63y9EMIn4cAP qSBcnqxeaLfAuA1ffR9lMYwqIMFY8E0/+tK4ROSxI/5+zNhM1NXZkCFT9J8XFr5LK47LxP /hMPdMbAuPPGv5Z5/0sJK0peCykYKO8= X-MC-Unique: uhvcrUSgN62LsAPCqw7NYA-1 X-Mimecast-MFC-AGG-ID: uhvcrUSgN62LsAPCqw7NYA_1749654408 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 09/27] vfio: mark posted writes in region write callbacks Date: Wed, 11 Jun 2025 17:06:01 +0200 Message-ID: <20250611150620.701903-10-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655185300116600 From: John Levon For vfio-user, the region write implementation needs to know if the write is posted; add the necessary plumbing to support this. Signed-off-by: John Levon Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250607001056.335310-5-john.levon= @nutanix.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-device.h | 4 ++-- include/hw/vfio/vfio-region.h | 1 + hw/vfio/device.c | 3 ++- hw/vfio/pci.c | 5 ++++- hw/vfio/region.c | 3 ++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index bf54fc69205a713263a666b480b2399e2a91f552..9793b2dba0ced9e87b1641ae783= 867ce1b41e71a 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -205,10 +205,10 @@ struct VFIODeviceIOOps { * @region_write * * Write @size bytes to the region @nr at offset @off from the buffer - * @data. + * @data; if @post, the write is posted. */ int (*region_write)(VFIODevice *vdev, uint8_t nr, off_t off, uint32_t = size, - void *data); + void *data, bool post); }; =20 void vfio_device_prepare(VFIODevice *vbasedev, VFIOContainerBase *bcontain= er, diff --git a/include/hw/vfio/vfio-region.h b/include/hw/vfio/vfio-region.h index cbffb269628cc89fbbdb060ce3ce6e45bd701bad..ede6e0c8f992caa3292d280474c= 90ddef27eb3dd 100644 --- a/include/hw/vfio/vfio-region.h +++ b/include/hw/vfio/vfio-region.h @@ -29,6 +29,7 @@ typedef struct VFIORegion { uint32_t nr_mmaps; VFIOMmap *mmaps; uint8_t nr; /* cache the region number for debug */ + bool post_wr; /* writes can be posted */ } VFIORegion; =20 =20 diff --git a/hw/vfio/device.c b/hw/vfio/device.c index a4bdde8e8bd49c82923d0d29a44f18fd71a44204..d32600eda1a282adaa4c58cfeb8= 0c19c6489ee92 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -543,7 +543,8 @@ static int vfio_device_io_region_read(VFIODevice *vbase= dev, uint8_t index, } =20 static int vfio_device_io_region_write(VFIODevice *vbasedev, uint8_t index, - off_t off, uint32_t size, void *dat= a) + off_t off, uint32_t size, void *dat= a, + bool post) { struct vfio_region_info *info; int ret; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 2901cedf6f3e4e1283cb59a1ff6c8ddb99a41b56..89f9246416a700ecbfb21ec3921= b5a71cadf9981 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -989,7 +989,7 @@ static int vfio_pci_config_space_write(VFIOPCIDevice *v= dev, off_t offset, { return vdev->vbasedev.io_ops->region_write(&vdev->vbasedev, VFIO_PCI_CONFIG_REGION_INDE= X, - offset, size, data); + offset, size, data, false); } =20 static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size) @@ -1793,6 +1793,9 @@ static void vfio_bar_prepare(VFIOPCIDevice *vdev, int= nr) bar->type =3D pci_bar & (bar->ioport ? ~PCI_BASE_ADDRESS_IO_MASK : ~PCI_BASE_ADDRESS_MEM_MASK); bar->size =3D bar->region.size; + + /* IO regions are sync, memory can be async */ + bar->region.post_wr =3D (bar->ioport =3D=3D 0); } =20 static void vfio_bars_prepare(VFIOPCIDevice *vdev) diff --git a/hw/vfio/region.c b/hw/vfio/region.c index cb172f2136dab7d5e649e588bda16b0e4821079d..f5b8e3cbf100f4f1b9fb9160756= 53d3a6e1ca8d4 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -66,7 +66,7 @@ void vfio_region_write(void *opaque, hwaddr addr, } =20 ret =3D vbasedev->io_ops->region_write(vbasedev, region->nr, - addr, size, &buf); + addr, size, &buf, region->post_wr= ); if (ret !=3D size) { error_report("%s(%s:region%d+0x%"HWADDR_PRIx", 0x%"PRIx64 ",%d) failed: %s", @@ -200,6 +200,7 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasedev= , VFIORegion *region, region->size =3D info->size; region->fd_offset =3D info->offset; region->nr =3D index; + region->post_wr =3D false; =20 if (region->size) { region->mem =3D g_new0(MemoryRegion, 1); --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654486; cv=none; d=zohomail.com; s=zohoarc; b=k5eJXYuvGmzEm9EAop3bwNbR9va9ZIVVeMJOA0CYdk2wnxVhecwi1x8ogya+Ve6q3SuS2cMR8+TiIH2bG6ANKchAAhg6kJ9FRbsG2dxhd/vmDhr35zYhrg4pOyqkVIazoi2ok6r+WD6KHlcf6LnKMYIhS372ETxEDS+dDufGZRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654486; 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=xBUbfm9uTQx5oUQ/Uoa0SNZZWU304PqkPdGaqXPqwF8=; b=ioKEcR++mJI3EOdPfhmk/Dgl6a2WJThvPWt5QV+/ZTaNl5szZMg0AGns2Erd0PwEgvyDGeJezOMZ8E5dYXfaX8m7fJ48vtNAZgJ3HFgACQajK9RXT1j0G7Fm5m07OGe8UhXh/ebQsUj3WwOJ62zYerWHXGeM01g7JMp9MKnaZWY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174965448636626.53482505935608; Wed, 11 Jun 2025 08:08:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2a-0004Wi-Ri; Wed, 11 Jun 2025 11:07:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2V-0004TT-W6 for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:56 -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 1uPN2U-00077K-BZ for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:55 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-449-rQKKFBv2O1KuEpNm9iLN4g-1; Wed, 11 Jun 2025 11:06:52 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3FBB719560AA; Wed, 11 Jun 2025 15:06:50 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C225180045B; Wed, 11 Jun 2025 15:06:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654413; 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=xBUbfm9uTQx5oUQ/Uoa0SNZZWU304PqkPdGaqXPqwF8=; b=QCbaiXZZ3Pr6yqH0aMBe6eXsyR23m88IrubhHCDgnrs12JZw5JdSgz001Z3r/6AYYhME2a /PaFt30cA73Lw9ORzMJ3WJ4hr7CTVf5fj3n/XIkfwsfFM6GJUGr7pBkbxSF8ai7wFhrRIv N73vR2eOmJjRVQZeu2s/CuJIqetqZyM= X-MC-Unique: rQKKFBv2O1KuEpNm9iLN4g-1 X-Mimecast-MFC-AGG-ID: rQKKFBv2O1KuEpNm9iLN4g_1749654410 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 10/27] migration: cpr helpers Date: Wed, 11 Jun 2025 17:06:02 +0200 Message-ID: <20250611150620.701903-11-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749654946920116600 From: Steve Sistare Add the cpr_incoming_needed, cpr_open_fd, and cpr_resave_fd helpers, for use when adding cpr support for vfio and iommufd. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-2-git-send-email-= steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/migration/cpr.h | 5 +++++ migration/cpr.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/migration/cpr.h b/include/migration/cpr.h index 7561fc75adc5e25f11726c199a22de831082d802..07858e93fa2fbd9ca0c31af2182= 16025c14369a6 100644 --- a/include/migration/cpr.h +++ b/include/migration/cpr.h @@ -18,6 +18,9 @@ void cpr_save_fd(const char *name, int id, int fd); void cpr_delete_fd(const char *name, int id); int cpr_find_fd(const char *name, int id); +void cpr_resave_fd(const char *name, int id, int fd); +int cpr_open_fd(const char *path, int flags, const char *name, int id, + Error **errp); =20 MigMode cpr_get_incoming_mode(void); void cpr_set_incoming_mode(MigMode mode); @@ -28,6 +31,8 @@ int cpr_state_load(MigrationChannel *channel, Error **err= p); void cpr_state_close(void); struct QIOChannel *cpr_state_ioc(void); =20 +bool cpr_incoming_needed(void *opaque); + QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp); QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp); =20 diff --git a/migration/cpr.c b/migration/cpr.c index 42c46563e522d43e68c49b2de7b4d45bb56bf662..a50a57edca754b50e68fa9c294b= 3c89791e62ba8 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -95,6 +95,36 @@ int cpr_find_fd(const char *name, int id) trace_cpr_find_fd(name, id, fd); return fd; } + +void cpr_resave_fd(const char *name, int id, int fd) +{ + CprFd *elem =3D find_fd(&cpr_state.fds, name, id); + int old_fd =3D elem ? elem->fd : -1; + + if (old_fd < 0) { + cpr_save_fd(name, id, fd); + } else if (old_fd !=3D fd) { + error_setg(&error_fatal, + "internal error: cpr fd '%s' id %d value %d " + "already saved with a different value %d", + name, id, fd, old_fd); + } +} + +int cpr_open_fd(const char *path, int flags, const char *name, int id, + Error **errp) +{ + int fd =3D cpr_find_fd(name, id); + + if (fd < 0) { + fd =3D qemu_open(path, flags, errp); + if (fd >=3D 0) { + cpr_save_fd(name, id, fd); + } + } + return fd; +} + /*************************************************************************/ #define CPR_STATE "CprState" =20 @@ -228,3 +258,9 @@ void cpr_state_close(void) cpr_state_file =3D NULL; } } + +bool cpr_incoming_needed(void *opaque) +{ + MigMode mode =3D migrate_mode(); + return mode =3D=3D MIG_MODE_CPR_TRANSFER; +} --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654470; cv=none; d=zohomail.com; s=zohoarc; b=jBZyqaqAR6fIrc7eSRq6IzB24bql/6WnokGqh4+7nQrZPZm2JTbolDfZ2/Ea4MjkzERUYSAVb4XtjgVqcNtpM2pDyaTUWxkDtVH5Vtb7CfyYiJL5myh0SCdSSwjvQ+1Smbg4Ib3AnutlfdO8Y7M2VykEvLqtadmNHTBii6MBQBA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654470; 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=9ghFrYcGKzo8WbE6moOqb9eH0dHqcHHVxhQWsNxMZpQ=; b=abpyJ/MFSrTGF8+28ur0hbx2Nm8Jvozywb8beW/nNEIABZVuZqluYy+n30weLiEgcXteakNecarqCkv4NALrearISR2+aM/6xm9xrYjuU+UL4pB7Dud0l0aDOOs8ZAUALXk07iqYX17AsuG7eDRWQtQ+ePAUDNtLMk5nPVNXOo8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654470207444.60188719060807; Wed, 11 Jun 2025 08:07:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2c-0004Wp-Jt; Wed, 11 Jun 2025 11:07:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2Z-0004VX-5N for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2X-00077o-DR for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:06:58 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-256-7DFRwzqAPHmAUHMkLvYo8A-1; Wed, 11 Jun 2025 11:06:55 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 33D5619560AA; Wed, 11 Jun 2025 15:06:53 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BF8F4180045C; Wed, 11 Jun 2025 15:06:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654416; 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=9ghFrYcGKzo8WbE6moOqb9eH0dHqcHHVxhQWsNxMZpQ=; b=NHQFA3aDU/due2sHNTjlIuQVMPZ4s274Ehg0gMAmPEbA2wsX4kxzx/dyb6aXaHimMtlstx wj1GQETGmNLloc40agVYp44NX6iZ5gPBahQQ/IvPDMxD/Ub1MLMtP1UpDP8rMT4MJiZhOD v1XMZdwr25eP7jPEOW9t9LG7jkjY59k= X-MC-Unique: 7DFRwzqAPHmAUHMkLvYo8A-1 X-Mimecast-MFC-AGG-ID: 7DFRwzqAPHmAUHMkLvYo8A_1749654413 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Fabiano Rosas , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 11/27] migration: lower handler priority Date: Wed, 11 Jun 2025 17:06:03 +0200 Message-ID: <20250611150620.701903-12-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749654795375116600 From: Steve Sistare Define a vmstate priority that is lower than the default, so its handlers run after all default priority handlers. Since 0 is no longer the default priority, translate an uninitialized priority of 0 to MIG_PRI_DEFAULT. CPR for vfio will use this to install handlers for containers that run after handlers for the devices that they contain. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas Reviewed-by: Peter Xu Link: https://lore.kernel.org/qemu-devel/1749569991-25171-3-git-send-email-= steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/migration/vmstate.h | 6 +++++- migration/savevm.c | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index a1dfab4460e9cffcce0df4562bd1cc420ff8cd85..1ff7bd9ac425ba67cd5ca7ad97b= cf570f9e19abe 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -155,7 +155,11 @@ enum VMStateFlags { }; =20 typedef enum { - MIG_PRI_DEFAULT =3D 0, + MIG_PRI_UNINITIALIZED =3D 0, /* An uninitialized priority field maps = to */ + /* MIG_PRI_DEFAULT in save_state_priority = */ + + MIG_PRI_LOW, /* Must happen after default */ + MIG_PRI_DEFAULT, MIG_PRI_IOMMU, /* Must happen before PCI devices */ MIG_PRI_PCI_BUS, /* Must happen before IOMMU */ MIG_PRI_VIRTIO_MEM, /* Must happen before IOMMU */ diff --git a/migration/savevm.c b/migration/savevm.c index 52105dd2f10b4a3223d23667b34c0fd0bcb8ca21..bb04a4520df9a443d90cf6cb52a= 383a5f053aaff 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -266,7 +266,7 @@ typedef struct SaveState { =20 static SaveState savevm_state =3D { .handlers =3D QTAILQ_HEAD_INITIALIZER(savevm_state.handlers), - .handler_pri_head =3D { [MIG_PRI_DEFAULT ... MIG_PRI_MAX] =3D NULL }, + .handler_pri_head =3D { [0 ... MIG_PRI_MAX] =3D NULL }, .global_section_id =3D 0, }; =20 @@ -737,7 +737,7 @@ static int calculate_compat_instance_id(const char *ids= tr) =20 static inline MigrationPriority save_state_priority(SaveStateEntry *se) { - if (se->vmsd) { + if (se->vmsd && se->vmsd->priority) { return se->vmsd->priority; } return MIG_PRI_DEFAULT; --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654732; cv=none; d=zohomail.com; s=zohoarc; b=AlNjUqpo/PJDctjq9hxA0drXUyAJPiNQuZtAP6wJXY9DUG03abRXqUP1twoMwbZ9OwIZ1FZ23hCDhAKfASOUWjWiQg9zRZ8/kgLfF85XP15vH+Gz9W68AI1LBxS+i3Bn61yJ3Kehg+511Lip4F2Sud8gJ8sDh5Vf82U56wBQcT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654732; 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=Feu0yBBfKVaJzO62UIhvSLbf/yLRlTpVAei5D3Fg23g=; b=mmcSdj2c3ESDxdnKucENiexNWooMB+wCA353zif+2nxjZKTU9OQ1CEVaR/hopRAtFbHbnMpldTGwHg79PRuu8BPSmPWRMAUE2QpyTaAPEgTnTP2IIyw40vwxUg76Pvip5c4eY0CH+O8uwH/48/SbeiaAUe4qzt0sh5D7+rNPJKQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174965473265014.882859707106377; Wed, 11 Jun 2025 08:12:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2e-0004hE-S7; Wed, 11 Jun 2025 11:07:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2b-0004Zl-Fz for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:02 -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 1uPN2Z-000784-D6 for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:01 -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-390-KPEltXStPZWKQRW9PB12Ug-1; Wed, 11 Jun 2025 11:06:56 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 57DB31956064; Wed, 11 Jun 2025 15:06:55 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B1F5E180045C; Wed, 11 Jun 2025 15:06:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654418; 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=Feu0yBBfKVaJzO62UIhvSLbf/yLRlTpVAei5D3Fg23g=; b=a/1cn3QhC/Tzt/WgmvP/POxmVD+QVO0yv0OQRYUKUa32+zAhh0ZljyimstZ4R5WIyA4kpy 6IGLlpe4PTwtEVWmV+s8n7BGejvZNcXD0d9HEK8ODVYIxXYe8tCAXCenSsUgN/Mmo8soy3 5yGQ48eUC7hrTI4ot70kpu4tCrp25Fs= X-MC-Unique: KPEltXStPZWKQRW9PB12Ug-1 X-Mimecast-MFC-AGG-ID: KPEltXStPZWKQRW9PB12Ug_1749654415 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 12/27] vfio/container: register container for cpr Date: Wed, 11 Jun 2025 17:06:04 +0200 Message-ID: <20250611150620.701903-13-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655269955116600 From: Steve Sistare Register a legacy container for cpr-transfer, replacing the generic CPR register call with a more specific legacy container register call. Add a blocker if the kernel does not support VFIO_UPDATE_VADDR or VFIO_UNMAP_ALL. This is mostly boiler plate. The fields to to saved and restored are added in subsequent patches. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-4-git-send-email-= steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container.h | 2 + include/hw/vfio/vfio-cpr.h | 15 +++++++ hw/vfio/container.c | 7 ++-- hw/vfio/cpr-legacy.c | 68 ++++++++++++++++++++++++++++++++ hw/vfio/cpr.c | 5 +-- hw/vfio/meson.build | 1 + 6 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 hw/vfio/cpr-legacy.c diff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-contai= ner.h index afc498da49fd4aa7625e47a0749f2c524049296d..21e5807e48e1be69a67fa864a7d= eddb141cb0cf7 100644 --- a/include/hw/vfio/vfio-container.h +++ b/include/hw/vfio/vfio-container.h @@ -10,6 +10,7 @@ #define HW_VFIO_CONTAINER_H =20 #include "hw/vfio/vfio-container-base.h" +#include "hw/vfio/vfio-cpr.h" =20 typedef struct VFIOContainer VFIOContainer; typedef struct VFIODevice VFIODevice; @@ -29,6 +30,7 @@ typedef struct VFIOContainer { int fd; /* /dev/vfio/vfio, empowered by the attached groups */ unsigned iommu_type; QLIST_HEAD(, VFIOGroup) group_list; + VFIOContainerCPR cpr; } VFIOContainer; =20 OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY); diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index 750ea5bcea38a953c781817f7e76a64422b79d4c..d4e0bd53c98f39a01f1d40fdc8b= fe1690166e9c8 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -9,8 +9,23 @@ #ifndef HW_VFIO_VFIO_CPR_H #define HW_VFIO_VFIO_CPR_H =20 +#include "migration/misc.h" + +struct VFIOContainer; struct VFIOContainerBase; =20 +typedef struct VFIOContainerCPR { + Error *blocker; +} VFIOContainerCPR; + + +bool vfio_legacy_cpr_register_container(struct VFIOContainer *container, + Error **errp); +void vfio_legacy_cpr_unregister_container(struct VFIOContainer *container); + +int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, MigrationEvent = *e, + Error **errp); + bool vfio_cpr_register_container(struct VFIOContainerBase *bcontainer, Error **errp); void vfio_cpr_unregister_container(struct VFIOContainerBase *bcontainer); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 0f948d024711062e2facf44b4d4694a0f1e59b83..93cdf80e13df8cc6f7a66a410b5= 273519af77280 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -33,7 +33,6 @@ #include "qapi/error.h" #include "pci.h" #include "hw/vfio/vfio-container.h" -#include "hw/vfio/vfio-cpr.h" #include "vfio-helpers.h" #include "vfio-listener.h" =20 @@ -643,7 +642,7 @@ static bool vfio_container_connect(VFIOGroup *group, Ad= dressSpace *as, new_container =3D true; bcontainer =3D &container->bcontainer; =20 - if (!vfio_cpr_register_container(bcontainer, errp)) { + if (!vfio_legacy_cpr_register_container(container, errp)) { goto fail; } =20 @@ -679,7 +678,7 @@ fail: vioc->release(bcontainer); } if (new_container) { - vfio_cpr_unregister_container(bcontainer); + vfio_legacy_cpr_unregister_container(container); object_unref(container); } if (fd >=3D 0) { @@ -720,7 +719,7 @@ static void vfio_container_disconnect(VFIOGroup *group) VFIOAddressSpace *space =3D bcontainer->space; =20 trace_vfio_container_disconnect(container->fd); - vfio_cpr_unregister_container(bcontainer); + vfio_legacy_cpr_unregister_container(container); close(container->fd); object_unref(container); =20 diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c new file mode 100644 index 0000000000000000000000000000000000000000..dd7ac84074c6fb12fb26e236263= bc1a0b865f06e --- /dev/null +++ b/hw/vfio/cpr-legacy.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021-2025 Oracle and/or its affiliates. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include "qemu/osdep.h" +#include "hw/vfio/vfio-container.h" +#include "migration/blocker.h" +#include "migration/cpr.h" +#include "migration/migration.h" +#include "migration/vmstate.h" +#include "qapi/error.h" + +static bool vfio_cpr_supported(VFIOContainer *container, Error **errp) +{ + if (!ioctl(container->fd, VFIO_CHECK_EXTENSION, VFIO_UPDATE_VADDR)) { + error_setg(errp, "VFIO container does not support VFIO_UPDATE_VADD= R"); + return false; + + } else if (!ioctl(container->fd, VFIO_CHECK_EXTENSION, VFIO_UNMAP_ALL)= ) { + error_setg(errp, "VFIO container does not support VFIO_UNMAP_ALL"); + return false; + + } else { + return true; + } +} + +static const VMStateDescription vfio_container_vmstate =3D { + .name =3D "vfio-container", + .version_id =3D 0, + .minimum_version_id =3D 0, + .needed =3D cpr_incoming_needed, + .fields =3D (VMStateField[]) { + VMSTATE_END_OF_LIST() + } +}; + +bool vfio_legacy_cpr_register_container(VFIOContainer *container, Error **= errp) +{ + VFIOContainerBase *bcontainer =3D &container->bcontainer; + Error **cpr_blocker =3D &container->cpr.blocker; + + migration_add_notifier_mode(&bcontainer->cpr_reboot_notifier, + vfio_cpr_reboot_notifier, + MIG_MODE_CPR_REBOOT); + + if (!vfio_cpr_supported(container, cpr_blocker)) { + return migrate_add_blocker_modes(cpr_blocker, errp, + MIG_MODE_CPR_TRANSFER, -1) =3D=3D= 0; + } + + vmstate_register(NULL, -1, &vfio_container_vmstate, container); + + return true; +} + +void vfio_legacy_cpr_unregister_container(VFIOContainer *container) +{ + VFIOContainerBase *bcontainer =3D &container->bcontainer; + + migration_remove_notifier(&bcontainer->cpr_reboot_notifier); + migrate_del_blocker(&container->cpr.blocker); + vmstate_unregister(NULL, &vfio_container_vmstate, container); +} diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index 0210e76a10993e0c01403fec51918cc9fca7b636..0e596122284507cb419cceabaf9= 0ca37871cd9f1 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -7,13 +7,12 @@ =20 #include "qemu/osdep.h" #include "hw/vfio/vfio-device.h" -#include "migration/misc.h" #include "hw/vfio/vfio-cpr.h" #include "qapi/error.h" #include "system/runstate.h" =20 -static int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, - MigrationEvent *e, Error **errp) +int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, + MigrationEvent *e, Error **errp) { if (e->type =3D=3D MIG_EVENT_PRECOPY_SETUP && !runstate_check(RUN_STATE_SUSPENDED) && !vm_get_suspended()) { diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index bccb05098ce18968caaa4d5d8dec3df0852d0398..73d29f925ff5c668518698effc3= e48cdf71c3a9a 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -21,6 +21,7 @@ system_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('= calxeda-xgmac.c')) system_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c')) system_ss.add(when: 'CONFIG_VFIO', if_true: files( 'cpr.c', + 'cpr-legacy.c', 'device.c', 'migration.c', 'migration-multifd.c', --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654461; cv=none; d=zohomail.com; s=zohoarc; b=lpU83Cv82pKUCfaKKsz9dc8asfecfxYj2PidfrAB4fTsSfBzzke7P3/sqcrtU0FUxrBNIX/TwA0JGdEmpyZEeu2wHvgHiOFMAEIBqULCioqfXf6KmBbPYXAu89ejsCdb/IblQLd+k5zC7RxdiFtY8fhQEdP91766skdSVNH2QHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654461; 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=krTSwMcwgTojtoWqP6DWRFs5VyrJ3ZJrofXJEj1Rfkw=; b=jheqvVURHd8lbE908a3fXRosHkKe6QBR/Drxr8rruomW7DyFo3WQ3qEWKovvk4rK13cJwJ3QD6bgK6mD4fB0W9gLVsLw17IotrmrdcBCzjP+cw44rvkVowgzi9yrSLQ7UgWuJ8mswsXjLpkORLJiP978t9wsGtLiKXUKr0zwYCA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17496544610471016.4219022227096; Wed, 11 Jun 2025 08:07:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2k-00053b-FJ; Wed, 11 Jun 2025 11:07:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2i-0004sb-BC for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:08 -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 1uPN2f-00078q-P3 for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:07 -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-152-vrMyL2tdPNWwOjrcqMsDCg-1; Wed, 11 Jun 2025 11:06:59 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 39956195608B; Wed, 11 Jun 2025 15:06:58 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D228D180045C; Wed, 11 Jun 2025 15:06:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654425; 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=krTSwMcwgTojtoWqP6DWRFs5VyrJ3ZJrofXJEj1Rfkw=; b=bKrgKExbg0x/mp0TN5b5myPO4Ym9Kq/m6unl1+dUsY4xOQXJZaOl5AKraV7q9OuNCC1ctN RSCBWaexmplilt8qjvnOamwnz09frvvILuNcIr3HeFn9U+L8Xwq+oZ1oXbVSLjwrB4xupd pgGMefn+yhMIBEiTwtiXRyGCQZbKbms= X-MC-Unique: vrMyL2tdPNWwOjrcqMsDCg-1 X-Mimecast-MFC-AGG-ID: vrMyL2tdPNWwOjrcqMsDCg_1749654418 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan Subject: [PULL 13/27] vfio/container: preserve descriptors Date: Wed, 11 Jun 2025 17:06:05 +0200 Message-ID: <20250611150620.701903-14-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749654693857116600 From: Steve Sistare At vfio creation time, save the value of vfio container, group, and device descriptors in CPR state. On qemu restart, vfio_realize() finds and uses the saved descriptors. During reuse, device and iommu state is already configured, so operations in vfio_realize that would modify the configuration, such as vfio ioctl's, are skipped. The result is that vfio_realize constructs qemu data structures that reflect the current state of the device. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1749569991-25171-5-git-send-email-= steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 6 ++++ hw/vfio/container.c | 67 +++++++++++++++++++++++++++++--------- hw/vfio/cpr-legacy.c | 42 ++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 15 deletions(-) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index d4e0bd53c98f39a01f1d40fdc8bfe1690166e9c8..5a2e5f6b21e690cf91fd731ff9a= a21a569f92f61 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -13,6 +13,7 @@ =20 struct VFIOContainer; struct VFIOContainerBase; +struct VFIOGroup; =20 typedef struct VFIOContainerCPR { Error *blocker; @@ -30,4 +31,9 @@ bool vfio_cpr_register_container(struct VFIOContainerBase= *bcontainer, Error **errp); void vfio_cpr_unregister_container(struct VFIOContainerBase *bcontainer); =20 +int vfio_cpr_group_get_device_fd(int d, const char *name); + +bool vfio_cpr_container_match(struct VFIOContainer *container, + struct VFIOGroup *group, int fd); + #endif /* HW_VFIO_VFIO_CPR_H */ diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 93cdf80e13df8cc6f7a66a410b5273519af77280..5caae4ccae59bf114f37a49019c= 40bb125ed4ba1 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -31,6 +31,8 @@ #include "system/reset.h" #include "trace.h" #include "qapi/error.h" +#include "migration/cpr.h" +#include "migration/blocker.h" #include "pci.h" #include "hw/vfio/vfio-container.h" #include "vfio-helpers.h" @@ -425,7 +427,12 @@ static VFIOContainer *vfio_create_container(int fd, VF= IOGroup *group, return NULL; } =20 - if (!vfio_set_iommu(fd, group->fd, &iommu_type, errp)) { + /* + * During CPR, just set the container type and skip the ioctls, as the + * container and group are already configured in the kernel. + */ + if (!cpr_is_incoming() && + !vfio_set_iommu(fd, group->fd, &iommu_type, errp)) { return NULL; } =20 @@ -592,6 +599,11 @@ static bool vfio_container_group_add(VFIOContainer *co= ntainer, VFIOGroup *group, group->container =3D container; QLIST_INSERT_HEAD(&container->group_list, group, container_next); vfio_group_add_kvm_device(group); + /* + * Remember the container fd for each group, so we can attach to the s= ame + * container after CPR. + */ + cpr_resave_fd("vfio_container_for_group", group->groupid, container->f= d); return true; } =20 @@ -601,6 +613,7 @@ static void vfio_container_group_del(VFIOContainer *con= tainer, VFIOGroup *group) group->container =3D NULL; vfio_group_del_kvm_device(group); vfio_ram_block_discard_disable(container, false); + cpr_delete_fd("vfio_container_for_group", group->groupid); } =20 static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as, @@ -615,17 +628,34 @@ static bool vfio_container_connect(VFIOGroup *group, = AddressSpace *as, bool group_was_added =3D false; =20 space =3D vfio_address_space_get(as); + fd =3D cpr_find_fd("vfio_container_for_group", group->groupid); =20 - QLIST_FOREACH(bcontainer, &space->containers, next) { - container =3D container_of(bcontainer, VFIOContainer, bcontainer); - if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) { - return vfio_container_group_add(container, group, errp); + if (!cpr_is_incoming()) { + QLIST_FOREACH(bcontainer, &space->containers, next) { + container =3D container_of(bcontainer, VFIOContainer, bcontain= er); + if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd= )) { + return vfio_container_group_add(container, group, errp); + } } - } =20 - fd =3D qemu_open("/dev/vfio/vfio", O_RDWR, errp); - if (fd < 0) { - goto fail; + fd =3D qemu_open("/dev/vfio/vfio", O_RDWR, errp); + if (fd < 0) { + goto fail; + } + } else { + /* + * For incoming CPR, the group is already attached in the kernel. + * If a container with matching fd is found, then update the + * userland group list and return. If not, then after the loop, + * create the container struct and group list. + */ + QLIST_FOREACH(bcontainer, &space->containers, next) { + container =3D container_of(bcontainer, VFIOContainer, bcontain= er); + + if (vfio_cpr_container_match(container, group, fd)) { + return vfio_container_group_add(container, group, errp); + } + } } =20 ret =3D ioctl(fd, VFIO_GET_API_VERSION); @@ -697,6 +727,7 @@ static void vfio_container_disconnect(VFIOGroup *group) =20 QLIST_REMOVE(group, container_next); group->container =3D NULL; + cpr_delete_fd("vfio_container_for_group", group->groupid); =20 /* * Explicitly release the listener first before unset container, @@ -750,7 +781,7 @@ static VFIOGroup *vfio_group_get(int groupid, AddressSp= ace *as, Error **errp) group =3D g_malloc0(sizeof(*group)); =20 snprintf(path, sizeof(path), "/dev/vfio/%d", groupid); - group->fd =3D qemu_open(path, O_RDWR, errp); + group->fd =3D cpr_open_fd(path, O_RDWR, "vfio_group", groupid, errp); if (group->fd < 0) { goto free_group_exit; } @@ -782,6 +813,7 @@ static VFIOGroup *vfio_group_get(int groupid, AddressSp= ace *as, Error **errp) return group; =20 close_fd_exit: + cpr_delete_fd("vfio_group", groupid); close(group->fd); =20 free_group_exit: @@ -803,6 +835,7 @@ static void vfio_group_put(VFIOGroup *group) vfio_container_disconnect(group); QLIST_REMOVE(group, next); trace_vfio_group_put(group->fd); + cpr_delete_fd("vfio_group", group->groupid); close(group->fd); g_free(group); } @@ -813,7 +846,7 @@ static bool vfio_device_get(VFIOGroup *group, const cha= r *name, g_autofree struct vfio_device_info *info =3D NULL; int fd; =20 - fd =3D ioctl(group->fd, VFIO_GROUP_GET_DEVICE_FD, name); + fd =3D vfio_cpr_group_get_device_fd(group->fd, name); if (fd < 0) { error_setg_errno(errp, errno, "error getting device from group %d", group->groupid); @@ -826,8 +859,7 @@ static bool vfio_device_get(VFIOGroup *group, const cha= r *name, info =3D vfio_get_device_info(fd); if (!info) { error_setg_errno(errp, errno, "error getting device info"); - close(fd); - return false; + goto fail; } =20 /* @@ -841,8 +873,7 @@ static bool vfio_device_get(VFIOGroup *group, const cha= r *name, if (!QLIST_EMPTY(&group->device_list)) { error_setg(errp, "Inconsistent setting of support for discardi= ng " "RAM (e.g., balloon) within group"); - close(fd); - return false; + goto fail; } =20 if (!group->ram_block_discard_allowed) { @@ -860,6 +891,11 @@ static bool vfio_device_get(VFIOGroup *group, const ch= ar *name, trace_vfio_device_get(name, info->flags, info->num_regions, info->num_= irqs); =20 return true; + +fail: + close(fd); + cpr_delete_fd(name, 0); + return false; } =20 static void vfio_device_put(VFIODevice *vbasedev) @@ -870,6 +906,7 @@ static void vfio_device_put(VFIODevice *vbasedev) QLIST_REMOVE(vbasedev, next); vbasedev->group =3D NULL; trace_vfio_device_put(vbasedev->fd); + cpr_delete_fd(vbasedev->name, 0); close(vbasedev->fd); } =20 diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c index dd7ac84074c6fb12fb26e236263bc1a0b865f06e..ac4a9ab315eab515607fb240503= 2ddc1ab980cf0 100644 --- a/hw/vfio/cpr-legacy.c +++ b/hw/vfio/cpr-legacy.c @@ -8,6 +8,7 @@ #include #include "qemu/osdep.h" #include "hw/vfio/vfio-container.h" +#include "hw/vfio/vfio-device.h" #include "migration/blocker.h" #include "migration/cpr.h" #include "migration/migration.h" @@ -66,3 +67,44 @@ void vfio_legacy_cpr_unregister_container(VFIOContainer = *container) migrate_del_blocker(&container->cpr.blocker); vmstate_unregister(NULL, &vfio_container_vmstate, container); } + +int vfio_cpr_group_get_device_fd(int d, const char *name) +{ + const int id =3D 0; + int fd =3D cpr_find_fd(name, id); + + if (fd < 0) { + fd =3D ioctl(d, VFIO_GROUP_GET_DEVICE_FD, name); + if (fd >=3D 0) { + cpr_save_fd(name, id, fd); + } + } + return fd; +} + +static bool same_device(int fd1, int fd2) +{ + struct stat st1, st2; + + return !fstat(fd1, &st1) && !fstat(fd2, &st2) && st1.st_dev =3D=3D st2= .st_dev; +} + +bool vfio_cpr_container_match(VFIOContainer *container, VFIOGroup *group, + int fd) +{ + if (container->fd =3D=3D fd) { + return true; + } + if (!same_device(container->fd, fd)) { + return false; + } + /* + * Same device, different fd. This occurs when the container fd is + * cpr_save'd multiple times, once for each groupid, so SCM_RIGHTS + * produces duplicates. De-dup it. + */ + cpr_delete_fd("vfio_container_for_group", group->groupid); + close(fd); + cpr_save_fd("vfio_container_for_group", group->groupid, container->fd); + return true; +} --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654704; cv=none; d=zohomail.com; s=zohoarc; b=jVSSAFtUC+vEDnh5IS/rXxuJQaVwecbDQ7mnRO8KdYC78w0SKzPeiHGaRXqTAPtdS2JCs6RoOLJ7uMWGckyIrXJD9CLz19cb7thUDe9DQIJ50qle9crV3IXLLB6KkxFhgMbAxlmm9OMd4KGWts+RXrxR4+Fe4qyWlQuR+Im2rw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654704; 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=yb4F3Uf4HAsSLHVJtGXLnO0swpN0pMYUu1KLQdQ3a+Q=; b=GAnAykhdxqHABK0rQp4v67/fIWucJCnRwihNpNX+r4Hie1hziGdAD4UuHB3x/y2dJXiQ4BJBtHvEU8FMlgwVzdvd7EbtAlCVBSBMB35eNgxDFSASH8imrC8Yh3jL6HZcDDtK2XR01JpO8yRy3TkOIPBtrZ9CbmcBiEGnv06Qhos= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174965470451676.60252734484664; Wed, 11 Jun 2025 08:11:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2j-0004y0-Cb; Wed, 11 Jun 2025 11:07:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2h-0004pk-VK for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:08 -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 1uPN2d-00078a-En for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:06 -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-323-29cn7PVWNQWXKxpyxxlnfw-1; Wed, 11 Jun 2025 11:07:01 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 88C611809C8A; Wed, 11 Jun 2025 15:07:00 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B6B61180045C; Wed, 11 Jun 2025 15:06:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654422; 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=yb4F3Uf4HAsSLHVJtGXLnO0swpN0pMYUu1KLQdQ3a+Q=; b=FLw6h/qdE2Yb2ZOR8rQATJ6Uk+oj/IRAfNFz7eca3za8JycVzg0/EMcRoSSEODhWqlDQm9 5PLHQ/5GqsfN1Gtu9c8zTv15BmgyYhL+BY/UutqKE2VpZjW6B+X3vyWW5Q5c7G+DEauavj MFhcloaP3f7Zamf3eGLgk25VILW2NLU= X-MC-Unique: 29cn7PVWNQWXKxpyxxlnfw-1 X-Mimecast-MFC-AGG-ID: 29cn7PVWNQWXKxpyxxlnfw_1749654420 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 14/27] vfio/container: discard old DMA vaddr Date: Wed, 11 Jun 2025 17:06:06 +0200 Message-ID: <20250611150620.701903-15-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655250033116600 From: Steve Sistare In the container pre_save handler, discard the virtual addresses in DMA mappings with VFIO_DMA_UNMAP_FLAG_VADDR, because guest RAM will be remapped at a different VA after in new QEMU. DMA to already-mapped pages continues. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-6-git-send-email-= steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/cpr-legacy.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c index ac4a9ab315eab515607fb2405032ddc1ab980cf0..ef106d0ea865e86e3fdce86928e= 987e812724a0e 100644 --- a/hw/vfio/cpr-legacy.c +++ b/hw/vfio/cpr-legacy.c @@ -15,6 +15,22 @@ #include "migration/vmstate.h" #include "qapi/error.h" =20 +static bool vfio_dma_unmap_vaddr_all(VFIOContainer *container, Error **err= p) +{ + struct vfio_iommu_type1_dma_unmap unmap =3D { + .argsz =3D sizeof(unmap), + .flags =3D VFIO_DMA_UNMAP_FLAG_VADDR | VFIO_DMA_UNMAP_FLAG_ALL, + .iova =3D 0, + .size =3D 0, + }; + if (ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, &unmap)) { + error_setg_errno(errp, errno, "vfio_dma_unmap_vaddr_all"); + return false; + } + return true; +} + + static bool vfio_cpr_supported(VFIOContainer *container, Error **errp) { if (!ioctl(container->fd, VFIO_CHECK_EXTENSION, VFIO_UPDATE_VADDR)) { @@ -30,10 +46,23 @@ static bool vfio_cpr_supported(VFIOContainer *container= , Error **errp) } } =20 +static int vfio_container_pre_save(void *opaque) +{ + VFIOContainer *container =3D opaque; + Error *local_err =3D NULL; + + if (!vfio_dma_unmap_vaddr_all(container, &local_err)) { + error_report_err(local_err); + return -1; + } + return 0; +} + static const VMStateDescription vfio_container_vmstate =3D { .name =3D "vfio-container", .version_id =3D 0, .minimum_version_id =3D 0, + .pre_save =3D vfio_container_pre_save, .needed =3D cpr_incoming_needed, .fields =3D (VMStateField[]) { VMSTATE_END_OF_LIST() --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654468; cv=none; d=zohomail.com; s=zohoarc; b=lcJEl+lmCXKqCVtgXp6wOgjvX9ke53YMzcDX3WDXChbAs1HlLk3VZtkZw/JxrtrFNsJwfOYSCJa55AJKVpOvdCv93hRqtCRUVviExiZMWgxi6REoD9I9gIKMUyMB7RMh/08IsidHvGr1Me2slv2FeFwh72kmrH3pSw69B2Kdwpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654468; 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=O3wgTLUn2fR2m5v//wDP/7WBTVXLyozQY2h0ba5Srzo=; b=A++0CFdNAZzO0tpO2IL42XA/8DYYVpslHt0rrGurJ+R/XxpbZRB4AO6v0Vab3yVQYy9Z3tILJ3k9mUc9KKm20m0bg+tEhy+z0PxO9SdLAsxo9thVaPKrDjSBWnPA/heOZfUgUFxklclhqLKzl1+O3Pr9Nyatr3KzkLYvpgGMCQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654468271874.6513345302119; Wed, 11 Jun 2025 08:07:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2m-0005G0-Iz; Wed, 11 Jun 2025 11:07:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2k-00052j-1A for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07: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 1uPN2i-00079E-3q for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:09 -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-224-zb2MflPXOJyK4ru2aQdGoQ-1; Wed, 11 Jun 2025 11:07:03 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 A81D018002A4; Wed, 11 Jun 2025 15:07:02 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 133E9180045C; Wed, 11 Jun 2025 15:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654427; 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=O3wgTLUn2fR2m5v//wDP/7WBTVXLyozQY2h0ba5Srzo=; b=K2HLqAr+mhJwYxdlJvoa0yQzzswu7/vLg+8C/FNCaKDDS0SDbq5OscdBwSUAZrNl0E19s5 ci4NfeeMTZO7fgEdHlHwN0hUwoKswTIWOrFVMqVXd8gEFCZK58qWbUJ54Q0PZBMUEV700B CJ/kGXS/lLKrkjeB7xujSjeKHSQrKFY= X-MC-Unique: zb2MflPXOJyK4ru2aQdGoQ-1 X-Mimecast-MFC-AGG-ID: zb2MflPXOJyK4ru2aQdGoQ_1749654422 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 15/27] vfio/container: restore DMA vaddr Date: Wed, 11 Jun 2025 17:06:07 +0200 Message-ID: <20250611150620.701903-16-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749654745063116600 From: Steve Sistare In new QEMU, do not register the memory listener at device creation time. Register it later, in the container post_load handler, after all vmstate that may affect regions and mapping boundaries has been loaded. The post_load registration will cause the listener to invoke its callback on each flat section, and the calls will match the mappings remembered by the kernel. The listener calls a special dma_map handler that passes the new VA of each section to the kernel using VFIO_DMA_MAP_FLAG_VADDR. Restore the normal handler at the end. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-7-git-send-email-= steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 3 ++ hw/vfio/container.c | 15 ++++++++-- hw/vfio/cpr-legacy.c | 57 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index 5a2e5f6b21e690cf91fd731ff9aa21a569f92f61..04624475f87361954a09ba3c9a4= 7cf1d8e7cc5b3 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -17,6 +17,9 @@ struct VFIOGroup; =20 typedef struct VFIOContainerCPR { Error *blocker; + int (*saved_dma_map)(const struct VFIOContainerBase *bcontainer, + hwaddr iova, ram_addr_t size, + void *vaddr, bool readonly, MemoryRegion *mr); } VFIOContainerCPR; =20 =20 diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 5caae4ccae59bf114f37a49019c40bb125ed4ba1..936ce37f190686b0875ed934ee2= 77d9e4ff8cb2f 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -136,6 +136,8 @@ static int vfio_legacy_dma_unmap_one(const VFIOContaine= rBase *bcontainer, int ret; Error *local_err =3D NULL; =20 + g_assert(!cpr_is_incoming()); + if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) { if (!vfio_container_devices_dirty_tracking_is_supported(bcontainer= ) && bcontainer->dirty_pages_supported) { @@ -690,8 +692,17 @@ static bool vfio_container_connect(VFIOGroup *group, A= ddressSpace *as, } group_was_added =3D true; =20 - if (!vfio_listener_register(bcontainer, errp)) { - goto fail; + /* + * If CPR, register the listener later, after all state that may + * affect regions and mapping boundaries has been cpr load'ed. Later, + * the listener will invoke its callback on each flat section and call + * dma_map to supply the new vaddr, and the calls will match the mappi= ngs + * remembered by the kernel. + */ + if (!cpr_is_incoming()) { + if (!vfio_listener_register(bcontainer, errp)) { + goto fail; + } } =20 bcontainer->initialized =3D true; diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c index ef106d0ea865e86e3fdce86928e987e812724a0e..2fd8348c7cd37964af87ef04e32= ce3dcd2bfde1a 100644 --- a/hw/vfio/cpr-legacy.c +++ b/hw/vfio/cpr-legacy.c @@ -9,11 +9,13 @@ #include "qemu/osdep.h" #include "hw/vfio/vfio-container.h" #include "hw/vfio/vfio-device.h" +#include "hw/vfio/vfio-listener.h" #include "migration/blocker.h" #include "migration/cpr.h" #include "migration/migration.h" #include "migration/vmstate.h" #include "qapi/error.h" +#include "qemu/error-report.h" =20 static bool vfio_dma_unmap_vaddr_all(VFIOContainer *container, Error **err= p) { @@ -30,6 +32,32 @@ static bool vfio_dma_unmap_vaddr_all(VFIOContainer *cont= ainer, Error **errp) return true; } =20 +/* + * Set the new @vaddr for any mappings registered during cpr load. + * The incoming state is cleared thereafter. + */ +static int vfio_legacy_cpr_dma_map(const VFIOContainerBase *bcontainer, + hwaddr iova, ram_addr_t size, void *vad= dr, + bool readonly, MemoryRegion *mr) +{ + const VFIOContainer *container =3D container_of(bcontainer, VFIOContai= ner, + bcontainer); + struct vfio_iommu_type1_dma_map map =3D { + .argsz =3D sizeof(map), + .flags =3D VFIO_DMA_MAP_FLAG_VADDR, + .vaddr =3D (__u64)(uintptr_t)vaddr, + .iova =3D iova, + .size =3D size, + }; + + g_assert(cpr_is_incoming()); + + if (ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map)) { + return -errno; + } + + return 0; +} =20 static bool vfio_cpr_supported(VFIOContainer *container, Error **errp) { @@ -58,11 +86,34 @@ static int vfio_container_pre_save(void *opaque) return 0; } =20 +static int vfio_container_post_load(void *opaque, int version_id) +{ + VFIOContainer *container =3D opaque; + VFIOContainerBase *bcontainer =3D &container->bcontainer; + VFIOGroup *group; + Error *local_err =3D NULL; + + if (!vfio_listener_register(bcontainer, &local_err)) { + error_report_err(local_err); + return -1; + } + + QLIST_FOREACH(group, &container->group_list, container_next) { + VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); + + /* Restore original dma_map function */ + vioc->dma_map =3D container->cpr.saved_dma_map; + } + return 0; +} + static const VMStateDescription vfio_container_vmstate =3D { .name =3D "vfio-container", .version_id =3D 0, .minimum_version_id =3D 0, + .priority =3D MIG_PRI_LOW, /* Must happen after devices and groups */ .pre_save =3D vfio_container_pre_save, + .post_load =3D vfio_container_post_load, .needed =3D cpr_incoming_needed, .fields =3D (VMStateField[]) { VMSTATE_END_OF_LIST() @@ -85,6 +136,12 @@ bool vfio_legacy_cpr_register_container(VFIOContainer *= container, Error **errp) =20 vmstate_register(NULL, -1, &vfio_container_vmstate, container); =20 + /* During incoming CPR, divert calls to dma_map. */ + if (cpr_is_incoming()) { + VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); + container->cpr.saved_dma_map =3D vioc->dma_map; + vioc->dma_map =3D vfio_legacy_cpr_dma_map; + } return true; } =20 --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654728; cv=none; d=zohomail.com; s=zohoarc; b=OMlbtpWAErCAYdm6CAhSoJyezoI1zSBLy1xkTscstRklZeXDTEq9nVj/68GQ/EgfUjDQBqf9VzfXuxS0Ro/U1hMjMzM45fouZ7M90mkFEkaJ6SFjB2idlzJovZj7kH2KqrPRtNPHnD65GywJ5uo0rV9u9C5VJDLPtq5YkK+Cn44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654728; 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=RMxtlPE7B4sju9qdm8kTdFAlyAtykB3GEclaldZ3V9E=; b=YwUfhqD6CxymJj2tfCIYrJ8mVYQXD4FwRhV2C9D9+zRj4PvMGDyPDhZ4EpovZQab1cZ3EE6iVDl57qEpwNmUWKYXAzZWWmOIGUHkr7yxCImCDzYhVBdcBWHdNtbNWXf6Df25xIp4ZWOf5wegQ9/RIDcespqMwjhn757NnOzNEOU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654728618667.0179965431863; Wed, 11 Jun 2025 08:12:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2n-0005LD-Jv; Wed, 11 Jun 2025 11:07:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2j-00050j-Fs for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:09 -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 1uPN2h-000794-OC for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:09 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-206-AlfbAGqcP3SavgiyDn12Eg-1; Wed, 11 Jun 2025 11:07:05 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C8831195608F; Wed, 11 Jun 2025 15:07:04 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 31EC1180045C; Wed, 11 Jun 2025 15:07:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654426; 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=RMxtlPE7B4sju9qdm8kTdFAlyAtykB3GEclaldZ3V9E=; b=OT3QqEijA5dko6cT8madOLui5lb7dOymihivy4DFGJ22eb4iG5xm994YFWa/3x/PMqLZj2 RBI2VJHt07iZ2UwUhhFz6y7FCDOQ/PHrL6KYl882EGke8s+/2YryQ8qqwae+Vv6Os+afpu a1eFBO3fyk26o+DW44bjkBMN/UOdUoI= X-MC-Unique: AlfbAGqcP3SavgiyDn12Eg-1 X-Mimecast-MFC-AGG-ID: AlfbAGqcP3SavgiyDn12Eg_1749654424 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 16/27] vfio/container: mdev cpr blocker Date: Wed, 11 Jun 2025 17:06:08 +0200 Message-ID: <20250611150620.701903-17-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655267783116600 From: Steve Sistare During CPR, after VFIO_DMA_UNMAP_FLAG_VADDR, the vaddr is temporarily invalid, so mediated devices cannot be supported. Add a blocker for them. This restriction will not apply to iommufd containers when CPR is added for them in a future patch. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-8-git-send-email-= steven.sistare@oracle.com [ clg: Fixed context change in VFIODevice ] Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 3 +++ include/hw/vfio/vfio-device.h | 2 ++ hw/vfio/container.c | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index 04624475f87361954a09ba3c9a47cf1d8e7cc5b3..b83dd4275183595aa31071d9909= 9ad746931c66a 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -22,6 +22,9 @@ typedef struct VFIOContainerCPR { void *vaddr, bool readonly, MemoryRegion *mr); } VFIOContainerCPR; =20 +typedef struct VFIODeviceCPR { + Error *mdev_blocker; +} VFIODeviceCPR; =20 bool vfio_legacy_cpr_register_container(struct VFIOContainer *container, Error **errp); diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 9793b2dba0ced9e87b1641ae783867ce1b41e71a..f39259406bdd7b4577c4c54cfb3= ac0dbbcedccb2 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -28,6 +28,7 @@ #endif #include "system/system.h" #include "hw/vfio/vfio-container-base.h" +#include "hw/vfio/vfio-cpr.h" #include "system/host_iommu_device.h" #include "system/iommufd.h" =20 @@ -86,6 +87,7 @@ typedef struct VFIODevice { QLIST_ENTRY(VFIODevice) hwpt_next; struct vfio_region_info **reginfo; int *region_fds; + VFIODeviceCPR cpr; } VFIODevice; =20 struct VFIODeviceOps { diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 936ce37f190686b0875ed934ee277d9e4ff8cb2f..3e8d645ebbd7b13c55625f38f42= 50670a63df124 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -987,6 +987,13 @@ static bool vfio_legacy_attach_device(const char *name= , VFIODevice *vbasedev, goto device_put_exit; } =20 + if (vbasedev->mdev) { + error_setg(&vbasedev->cpr.mdev_blocker, + "CPR does not support vfio mdev %s", vbasedev->name); + migrate_add_blocker_modes(&vbasedev->cpr.mdev_blocker, &error_fata= l, + MIG_MODE_CPR_TRANSFER, -1); + } + return true; =20 device_put_exit: @@ -1004,6 +1011,7 @@ static void vfio_legacy_detach_device(VFIODevice *vba= sedev) =20 vfio_device_unprepare(vbasedev); =20 + migrate_del_blocker(&vbasedev->cpr.mdev_blocker); object_unref(vbasedev->hiod); vfio_device_put(vbasedev); vfio_group_put(group); --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654491; cv=none; d=zohomail.com; s=zohoarc; b=Uf2ntqUNKEje5Al3oplmLl8Soktx/dfmkT21B38/DtFZOX7Gwv4c5t3usxqViv77rjPeTXFNMzBvIG3/7QUGAebWYrZofqn5ajEPns051ZasJoGRyT9F8t83rG/ncUL/Sf3patEX5hoCcyY3RhLiz1nv+6nTEWu593xtJJO4uFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654491; 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=7Mncl3eIe35qDtefYpoRq5zfuIlzvDpPbzDgAjgPdLc=; b=dgOwHi6W0aueDQHof9uxdvwlVhtGR5YmawYQ5iX9qzL9A8oPOoiYjygSvwagyp6MVmOCPkhxkOudIKQ8IGsD9pnUqui7yltoHJNxBLnn177Yg4k4XoL/ckrWtWubrze4SfYpREdZHwd5TS1bl0exWpESfojQuNN3Pl9+26DqA5A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654491426652.9218433517191; Wed, 11 Jun 2025 08:08:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2p-0005S9-Ro; Wed, 11 Jun 2025 11:07:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2m-0005H9-Hb for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07: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 1uPN2k-00079l-8u for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:12 -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-640-BoZ7ku3CNISfbKCe2NM4_g-1; Wed, 11 Jun 2025 11:07:07 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 E7CDD1800282; Wed, 11 Jun 2025 15:07:06 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 528CC180045C; Wed, 11 Jun 2025 15:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654429; 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=7Mncl3eIe35qDtefYpoRq5zfuIlzvDpPbzDgAjgPdLc=; b=QFcF+PVqmK+ZymRLo1IMrN77IFdvij2ZWzG43YgmQVh8qg4UJIdrHmm4laoH2SI8pn/Tth vGvh2D2jfzbCzMdWLw6WoUqLUDhuwCC2SXFY7eCYfQ4JxEOq5kaJCu4fncMz2SeGqTsIaw 0kZyyGoDHpE/IPZ89bpdn8g3qw7P9tI= X-MC-Unique: BoZ7ku3CNISfbKCe2NM4_g-1 X-Mimecast-MFC-AGG-ID: BoZ7ku3CNISfbKCe2NM4_g_1749654427 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 17/27] vfio/container: recover from unmap-all-vaddr failure Date: Wed, 11 Jun 2025 17:06:09 +0200 Message-ID: <20250611150620.701903-18-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655095993116600 From: Steve Sistare If there are multiple containers and unmap-all fails for some container, we need to remap vaddr for the other containers for which unmap-all succeeded. Recover by walking all address ranges of all containers to restore the vaddr for each. Do so by invoking the vfio listener callback, and passing a new "remap" flag that tells it to restore a mapping without re-allocating new userland data structures. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-9-git-send-email-= steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 3 + include/hw/vfio/vfio-cpr.h | 10 +++ hw/vfio/cpr-legacy.c | 91 +++++++++++++++++++++++++++ hw/vfio/listener.c | 19 +++++- 4 files changed, 122 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 9d37f86115a873eb164ae90c5ebaf2acd2c6a5d8..f0232654eedf19c4d9c4f0ed55e= 79074442720c3 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -256,4 +256,7 @@ struct VFIOIOMMUClass { VFIORamDiscardListener *vfio_find_ram_discard_listener( VFIOContainerBase *bcontainer, MemoryRegionSection *section); =20 +void vfio_container_region_add(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, bool cpr_rema= p); + #endif /* HW_VFIO_VFIO_CONTAINER_BASE_H */ diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index b83dd4275183595aa31071d99099ad746931c66a..56ede049ad68759e31d855809c5= bd8493dc09176 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -10,6 +10,7 @@ #define HW_VFIO_VFIO_CPR_H =20 #include "migration/misc.h" +#include "system/memory.h" =20 struct VFIOContainer; struct VFIOContainerBase; @@ -17,6 +18,9 @@ struct VFIOGroup; =20 typedef struct VFIOContainerCPR { Error *blocker; + bool vaddr_unmapped; + NotifierWithReturn transfer_notifier; + MemoryListener remap_listener; int (*saved_dma_map)(const struct VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly, MemoryRegion *mr); @@ -42,4 +46,10 @@ int vfio_cpr_group_get_device_fd(int d, const char *name= ); bool vfio_cpr_container_match(struct VFIOContainer *container, struct VFIOGroup *group, int fd); =20 +void vfio_cpr_giommu_remap(struct VFIOContainerBase *bcontainer, + MemoryRegionSection *section); + +bool vfio_cpr_ram_discard_register_listener( + struct VFIOContainerBase *bcontainer, MemoryRegionSection *section); + #endif /* HW_VFIO_VFIO_CPR_H */ diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c index 2fd8348c7cd37964af87ef04e32ce3dcd2bfde1a..a84c3247b7172a1f084659f2418= d0c1e1394becf 100644 --- a/hw/vfio/cpr-legacy.c +++ b/hw/vfio/cpr-legacy.c @@ -29,6 +29,7 @@ static bool vfio_dma_unmap_vaddr_all(VFIOContainer *conta= iner, Error **errp) error_setg_errno(errp, errno, "vfio_dma_unmap_vaddr_all"); return false; } + container->cpr.vaddr_unmapped =3D true; return true; } =20 @@ -59,6 +60,14 @@ static int vfio_legacy_cpr_dma_map(const VFIOContainerBa= se *bcontainer, return 0; } =20 +static void vfio_region_remap(MemoryListener *listener, + MemoryRegionSection *section) +{ + VFIOContainer *container =3D container_of(listener, VFIOContainer, + cpr.remap_listener); + vfio_container_region_add(&container->bcontainer, section, true); +} + static bool vfio_cpr_supported(VFIOContainer *container, Error **errp) { if (!ioctl(container->fd, VFIO_CHECK_EXTENSION, VFIO_UPDATE_VADDR)) { @@ -120,6 +129,40 @@ static const VMStateDescription vfio_container_vmstate= =3D { } }; =20 +static int vfio_cpr_fail_notifier(NotifierWithReturn *notifier, + MigrationEvent *e, Error **errp) +{ + VFIOContainer *container =3D + container_of(notifier, VFIOContainer, cpr.transfer_notifier); + VFIOContainerBase *bcontainer =3D &container->bcontainer; + + if (e->type !=3D MIG_EVENT_PRECOPY_FAILED) { + return 0; + } + + if (container->cpr.vaddr_unmapped) { + /* + * Force a call to vfio_region_remap for each mapped section by + * temporarily registering a listener, and temporarily diverting + * dma_map to vfio_legacy_cpr_dma_map. The latter restores vaddr. + */ + + VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); + vioc->dma_map =3D vfio_legacy_cpr_dma_map; + + container->cpr.remap_listener =3D (MemoryListener) { + .name =3D "vfio cpr recover", + .region_add =3D vfio_region_remap + }; + memory_listener_register(&container->cpr.remap_listener, + bcontainer->space->as); + memory_listener_unregister(&container->cpr.remap_listener); + container->cpr.vaddr_unmapped =3D false; + vioc->dma_map =3D container->cpr.saved_dma_map; + } + return 0; +} + bool vfio_legacy_cpr_register_container(VFIOContainer *container, Error **= errp) { VFIOContainerBase *bcontainer =3D &container->bcontainer; @@ -142,6 +185,10 @@ bool vfio_legacy_cpr_register_container(VFIOContainer = *container, Error **errp) container->cpr.saved_dma_map =3D vioc->dma_map; vioc->dma_map =3D vfio_legacy_cpr_dma_map; } + + migration_add_notifier_mode(&container->cpr.transfer_notifier, + vfio_cpr_fail_notifier, + MIG_MODE_CPR_TRANSFER); return true; } =20 @@ -152,6 +199,50 @@ void vfio_legacy_cpr_unregister_container(VFIOContaine= r *container) migration_remove_notifier(&bcontainer->cpr_reboot_notifier); migrate_del_blocker(&container->cpr.blocker); vmstate_unregister(NULL, &vfio_container_vmstate, container); + migration_remove_notifier(&container->cpr.transfer_notifier); +} + +/* + * In old QEMU, VFIO_DMA_UNMAP_FLAG_VADDR may fail on some mapping after + * succeeding for others, so the latter have lost their vaddr. Call this + * to restore vaddr for a section with a giommu. + * + * The giommu already exists. Find it and replay it, which calls + * vfio_legacy_cpr_dma_map further down the stack. + */ +void vfio_cpr_giommu_remap(VFIOContainerBase *bcontainer, + MemoryRegionSection *section) +{ + VFIOGuestIOMMU *giommu =3D NULL; + hwaddr as_offset =3D section->offset_within_address_space; + hwaddr iommu_offset =3D as_offset - section->offset_within_region; + + QLIST_FOREACH(giommu, &bcontainer->giommu_list, giommu_next) { + if (giommu->iommu_mr =3D=3D IOMMU_MEMORY_REGION(section->mr) && + giommu->iommu_offset =3D=3D iommu_offset) { + break; + } + } + g_assert(giommu); + memory_region_iommu_replay(giommu->iommu_mr, &giommu->n); +} + +/* + * In old QEMU, VFIO_DMA_UNMAP_FLAG_VADDR may fail on some mapping after + * succeeding for others, so the latter have lost their vaddr. Call this + * to restore vaddr for a section with a RamDiscardManager. + * + * The ram discard listener already exists. Call its populate function + * directly, which calls vfio_legacy_cpr_dma_map. + */ +bool vfio_cpr_ram_discard_register_listener(VFIOContainerBase *bcontainer, + MemoryRegionSection *section) +{ + VFIORamDiscardListener *vrdl =3D + vfio_find_ram_discard_listener(bcontainer, section); + + g_assert(vrdl); + return vrdl->listener.notify_populate(&vrdl->listener, section) =3D=3D= 0; } =20 int vfio_cpr_group_get_device_fd(int d, const char *name) diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 735b5f21b7b87cff6b5e757f9696d9a7c1c44fbf..f498e23a93747cb1826726f7c4c= a28f8128b4ced 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -481,6 +481,13 @@ static void vfio_listener_region_add(MemoryListener *l= istener, { VFIOContainerBase *bcontainer =3D container_of(listener, VFIOContainer= Base, listener); + vfio_container_region_add(bcontainer, section, false); +} + +void vfio_container_region_add(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, + bool cpr_remap) +{ hwaddr iova, end; Int128 llend, llsize; void *vaddr; @@ -516,6 +523,11 @@ static void vfio_listener_region_add(MemoryListener *l= istener, int iommu_idx; =20 trace_vfio_listener_region_add_iommu(section->mr->name, iova, end); + + if (cpr_remap) { + vfio_cpr_giommu_remap(bcontainer, section); + } + /* * FIXME: For VFIO iommu types which have KVM acceleration to * avoid bouncing all map/unmaps through qemu this way, this @@ -558,7 +570,12 @@ static void vfio_listener_region_add(MemoryListener *l= istener, * about changes. */ if (memory_region_has_ram_discard_manager(section->mr)) { - vfio_ram_discard_register_listener(bcontainer, section); + if (!cpr_remap) { + vfio_ram_discard_register_listener(bcontainer, section); + } else if (!vfio_cpr_ram_discard_register_listener(bcontainer, + section)) { + goto fail; + } return; } =20 --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654470; cv=none; d=zohomail.com; s=zohoarc; b=StMEZsXKcH1QmH3O2jg+WxOOhmz9wc57+wEepnDWZpkxSPor0/ut8FRJxOEr+4WoJSh09HolGGhQN1002Van8Ci5fPqlGjOqgpW6FrrNFIpca4CBzyasNwsqG8VUm7+JezJWuFlyhqMOaswfdBm+YKLbpgwly9E/EgG6fNITlMQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654470; 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=bId16bWCKc0w7Q0PZ88SUxs3+6VkDWy1vjtV7LYIp1E=; b=e+LvBmovL7FQJTTG2dT5gTI3/kfbghs5CMzmxsNUDoAbrm/G6N+6WUbHjB6jVOY4vBxlm/QBOIqFXJ3cYzHPBQqlPHE9Lo4OV/8LmDr14V+kPSOjbly3iCswkXulpe1xMKmY2cD/bLZSA7Wl9U/27wA4ZLW9wzxObFa/Aidzceo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654470684741.3352203658902; Wed, 11 Jun 2025 08:07:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN2s-0005WA-04; Wed, 11 Jun 2025 11:07:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2o-0005Ol-4h for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:14 -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 1uPN2m-0007A9-Jv for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07: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-126-ypwtfhSwMSKWOyilrjXp-g-1; Wed, 11 Jun 2025 11:07:10 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 9695219560A2; Wed, 11 Jun 2025 15:07:09 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 71DDB18002B6; Wed, 11 Jun 2025 15:07:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654431; 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=bId16bWCKc0w7Q0PZ88SUxs3+6VkDWy1vjtV7LYIp1E=; b=PVeRnh2mth/p3bDDy08eNCslkNemCjukRyCcjTIj1i73ejUNIpBjVhQ/zIuQ/etPW2SUy+ twjv+Cp6yX7qlLQQud85TzURSS1nA0rHhBm29oHzrndCf+8YYxP84qnB1CSOuitz7hfERJ 5Q0q4D8OPjQYDdDFugPhzn5a3nY9kTE= X-MC-Unique: ypwtfhSwMSKWOyilrjXp-g-1 X-Mimecast-MFC-AGG-ID: ypwtfhSwMSKWOyilrjXp-g_1749654429 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 18/27] pci: export msix_is_pending Date: Wed, 11 Jun 2025 17:06:10 +0200 Message-ID: <20250611150620.701903-19-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749654846500116600 From: Steve Sistare Export msix_is_pending for use by cpr. No functional change. Signed-off-by: Steve Sistare Acked-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/1749569991-25171-10-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/pci/msix.h | 1 + hw/pci/msix.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/hw/pci/msix.h b/include/hw/pci/msix.h index 0e6f257e4511e9e48a31bd71e0fa7d74a245c59f..11ef9454c130e89a1055615bbaa= 295ffde89d805 100644 --- a/include/hw/pci/msix.h +++ b/include/hw/pci/msix.h @@ -32,6 +32,7 @@ int msix_present(PCIDevice *dev); bool msix_is_masked(PCIDevice *dev, unsigned vector); void msix_set_pending(PCIDevice *dev, unsigned vector); void msix_clr_pending(PCIDevice *dev, int vector); +int msix_is_pending(PCIDevice *dev, unsigned vector); =20 void msix_vector_use(PCIDevice *dev, unsigned vector); void msix_vector_unuse(PCIDevice *dev, unsigned vector); diff --git a/hw/pci/msix.c b/hw/pci/msix.c index 66f27b9d7120f10e413ac18fb9413e111c1ab508..8c7f6709e2a154da98c7f69d6f5= dc0d6dddef4b9 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -72,7 +72,7 @@ static uint8_t *msix_pending_byte(PCIDevice *dev, int vec= tor) return dev->msix_pba + vector / 8; } =20 -static int msix_is_pending(PCIDevice *dev, int vector) +int msix_is_pending(PCIDevice *dev, unsigned int vector) { return *msix_pending_byte(dev, vector) & msix_pending_mask(vector); } --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654471; cv=none; d=zohomail.com; s=zohoarc; b=AAUC+sHTZ0P3NwZLqQdtqoy57z6VGbnBTZN9BKg+62b32+E1zgXyf6ZMTDjoXUFHyB0mjN1Hz6Qj0nqmN7oVLR5nIgJCH1BvamTvBrQ9vV+C3V++D2uVWDDdp/gVT/c3uvy1JVfDs6uRyKrd3Kmr+81fNP4QADcI4s4ZOSyNf4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654471; 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=sOK6h25bc1ZM6IXxN8YLXSfPeGR1jIW7GAUe4FyrHkw=; b=ilVLC52IC1vk9S4Ka0EZJtfPPbyJIogExAJs76axQAB/9o7fxu5uuJIXEV7CFF5fdIxhMzR2XTG22hPm76QdDtdHXDXyKKr2K/rfEYGZzpY1ByTnvA2jfDjeEA2YTeFM3/CFHKyawaaC6LZ2+hEx85rMGuhJa4BaPUw6fTl/hDg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654471371956.6771320896378; Wed, 11 Jun 2025 08:07:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN30-0005ZY-UG; Wed, 11 Jun 2025 11:07:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2r-0005Wq-Vo for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07: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 1uPN2q-0007Af-8b for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:17 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-218-1Q0qf0_6NcSrwuZqUxnctg-1; Wed, 11 Jun 2025 11:07:14 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 03EB1195608E; Wed, 11 Jun 2025 15:07:12 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1FFEB180045B; Wed, 11 Jun 2025 15:07:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654435; 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=sOK6h25bc1ZM6IXxN8YLXSfPeGR1jIW7GAUe4FyrHkw=; b=YNnpIRpOknAQebqfatC73eZIcUnWR6rUtegVnuKLOlGjDe26rhofZOaxW7tdgL89T5hw95 yoKmse/uVMA9pffAmcyIpTXWSvQTsbDkD+Ti1Ix/fYVvmwM2SrhX0HCdbDOo+F9YSWmUV3 H3jV0AhqlP4pPzmyA8EiN0wWaZljJqU= X-MC-Unique: 1Q0qf0_6NcSrwuZqUxnctg-1 X-Mimecast-MFC-AGG-ID: 1Q0qf0_6NcSrwuZqUxnctg_1749654432 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , "Michael S. Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 19/27] pci: skip reset during cpr Date: Wed, 11 Jun 2025 17:06:11 +0200 Message-ID: <20250611150620.701903-20-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749654895647116600 From: Steve Sistare Do not reset a vfio-pci device during CPR. Signed-off-by: Steve Sistare Acked-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/1749576403-25355-1-git-send-email-= steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/pci/pci.h | 2 ++ hw/pci/pci.c | 5 +++++ hw/vfio/pci.c | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 35d59d7672e2b9ca43ae2f9708e94a07c04f9784..df3cc7b8750014454bd5ab4c3e9= a3feca122eca3 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -222,6 +222,8 @@ enum { QEMU_PCIE_EXT_TAG =3D (1 << QEMU_PCIE_EXT_TAG_BITNR), #define QEMU_PCI_CAP_PM_BITNR 14 QEMU_PCI_CAP_PM =3D (1 << QEMU_PCI_CAP_PM_BITNR), +#define QEMU_PCI_SKIP_RESET_ON_CPR_BITNR 15 + QEMU_PCI_SKIP_RESET_ON_CPR =3D (1 << QEMU_PCI_SKIP_RESET_ON_CPR_BITNR), }; =20 typedef struct PCIINTxRoute { diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 9b4bf48439ed225e6b443f067928a84950f12a88..c70b5ceebaf1f2b10768bd03052= 6cbb518da2b8d 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -32,6 +32,7 @@ #include "hw/pci/pci_host.h" #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" +#include "migration/cpr.h" #include "migration/qemu-file-types.h" #include "migration/vmstate.h" #include "net/net.h" @@ -537,6 +538,10 @@ static void pci_reset_regions(PCIDevice *dev) =20 static void pci_do_device_reset(PCIDevice *dev) { + if ((dev->cap_present & QEMU_PCI_SKIP_RESET_ON_CPR) && cpr_is_incoming= ()) { + return; + } + pci_device_deassert_intx(dev); assert(dev->irq_state =3D=3D 0); =20 diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 89f9246416a700ecbfb21ec3921b5a71cadf9981..b97261c61b4f303cb799e4ed6cd= ce391c198353c 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3411,6 +3411,13 @@ static void vfio_instance_init(Object *obj) /* QEMU_PCI_CAP_EXPRESS initialization does not depend on QEMU command * line, therefore, no need to wait to realize like other devices */ pci_dev->cap_present |=3D QEMU_PCI_CAP_EXPRESS; + + /* + * A device that is resuming for cpr is already configured, so do not + * reset it during qemu_system_reset prior to cpr load, else interrupts + * may be lost. + */ + pci_dev->cap_present |=3D QEMU_PCI_SKIP_RESET_ON_CPR; } =20 static void vfio_pci_base_dev_class_init(ObjectClass *klass, const void *d= ata) --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654686; cv=none; d=zohomail.com; s=zohoarc; b=al9G9g3Jvk4qKDG/+3Zd08goeXhaLJsHigGKWhowzXWhYnAt+pW9xzqjO6yXmXy+0BZDPJ74q7pkGMugcua/ddN1JLp8b7p7Ogzp+WehBro5yD8Cl2tQU0T7UCCC6xfeN1oQIL2FrhvspPqhmiWuLFVPbunx1M5yYri1j/9K33Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654686; 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=voVPz9bppXe4ojOkmZSq1ah1isRPLqgbpzeFf+0RIgM=; b=JhDge9KPz0V2Y2NSWnnK0/e2fQt9JbZXwyqv/iclTFKhlRd9z7bO3SFAAp/hXazNHu9giIk5zXbNhhOZp58WYITod60v17wEhOrlKak3UEXO9x2GDiiFxrWNHOazwgDR0B/SFRniDlVi01Ka+go8IPaw+YHR527+q0c5USM6ksk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174965468603364.7246819202121; Wed, 11 Jun 2025 08:11:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN38-0005gr-Jz; Wed, 11 Jun 2025 11:07:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2t-0005YB-Cj for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:21 -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 1uPN2r-0007Aq-DP for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:19 -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-540-hbZnV96AOquNoWY6nWxsqg-1; Wed, 11 Jun 2025 11:07:15 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 9C4781956095; Wed, 11 Jun 2025 15:07:14 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 81F0C180045C; Wed, 11 Jun 2025 15:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654436; 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=voVPz9bppXe4ojOkmZSq1ah1isRPLqgbpzeFf+0RIgM=; b=cVQSqNIQHFUX9Syifx3CXV8Ut6vThTBB2/OzhCaSUAnwWxRbmjLzBs8jWQz45KM5T9iZe1 fykULtebJmjagpjRQhW3WyUb+E2Cd8irCCA/e0QEkeVY7q/GJKvOIe/DVh7eFTzu1TFCqf Ur3Jf6pkj1hfKdqkzKCqvyZD7fucUqU= X-MC-Unique: hbZnV96AOquNoWY6nWxsqg-1 X-Mimecast-MFC-AGG-ID: hbZnV96AOquNoWY6nWxsqg_1749654434 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 20/27] vfio-pci: skip reset during cpr Date: Wed, 11 Jun 2025 17:06:12 +0200 Message-ID: <20250611150620.701903-21-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655241325116600 From: Steve Sistare Do not reset a vfio-pci device during CPR, and do not complain if the kernel's PCI config space changes for non-emulated bits between the vmstate save and load, which can happen due to ongoing interrupt activity. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-12-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 2 ++ hw/vfio/cpr.c | 31 +++++++++++++++++++++++++++++++ hw/vfio/pci.c | 7 +++++++ 3 files changed, 40 insertions(+) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index 56ede049ad68759e31d855809c5bd8493dc09176..8bf85b9f4ec2cd712ef835dc5d7= 20fe03d767d03 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -52,4 +52,6 @@ void vfio_cpr_giommu_remap(struct VFIOContainerBase *bcon= tainer, bool vfio_cpr_ram_discard_register_listener( struct VFIOContainerBase *bcontainer, MemoryRegionSection *section); =20 +extern const VMStateDescription vfio_cpr_pci_vmstate; + #endif /* HW_VFIO_VFIO_CPR_H */ diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index 0e596122284507cb419cceabaf90ca37871cd9f1..fdbb58e2039e9fc6bd91c37a0f5= 34522c0987680 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -8,6 +8,8 @@ #include "qemu/osdep.h" #include "hw/vfio/vfio-device.h" #include "hw/vfio/vfio-cpr.h" +#include "hw/vfio/pci.h" +#include "migration/cpr.h" #include "qapi/error.h" #include "system/runstate.h" =20 @@ -37,3 +39,32 @@ void vfio_cpr_unregister_container(VFIOContainerBase *bc= ontainer) { migration_remove_notifier(&bcontainer->cpr_reboot_notifier); } + +/* + * The kernel may change non-emulated config bits. Exclude them from the + * changed-bits check in get_pci_config_device. + */ +static int vfio_cpr_pci_pre_load(void *opaque) +{ + VFIOPCIDevice *vdev =3D opaque; + PCIDevice *pdev =3D &vdev->pdev; + int size =3D MIN(pci_config_size(pdev), vdev->config_size); + int i; + + for (i =3D 0; i < size; i++) { + pdev->cmask[i] &=3D vdev->emulated_config_bits[i]; + } + + return 0; +} + +const VMStateDescription vfio_cpr_pci_vmstate =3D { + .name =3D "vfio-cpr-pci", + .version_id =3D 0, + .minimum_version_id =3D 0, + .pre_load =3D vfio_cpr_pci_pre_load, + .needed =3D cpr_incoming_needed, + .fields =3D (VMStateField[]) { + VMSTATE_END_OF_LIST() + } +}; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index b97261c61b4f303cb799e4ed6cdce391c198353c..2da5989581e72538cf61de3f453= 070b5e4f53cc4 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -30,6 +30,7 @@ #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" #include "migration/vmstate.h" +#include "migration/cpr.h" #include "qobject/qdict.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" @@ -3354,6 +3355,11 @@ static void vfio_pci_reset(DeviceState *dev) { VFIOPCIDevice *vdev =3D VFIO_PCI_BASE(dev); =20 + /* Do not reset the device during qemu_system_reset prior to cpr load = */ + if (cpr_is_incoming()) { + return; + } + trace_vfio_pci_reset(vdev->vbasedev.name); =20 vfio_pci_pre_reset(vdev); @@ -3530,6 +3536,7 @@ static void vfio_pci_dev_class_init(ObjectClass *klas= s, const void *data) #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; =20 --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654678; cv=none; d=zohomail.com; s=zohoarc; b=WAgMkw8ImPyK6PU24W4rnkWirxa0MpsO/y0cYuD5XuesrHOdWrm0bbvK/ggCjrjkWcTuLOA7c1OrbApNYHBfJrwf6+crlDoGJb6znyoAQsoZTyPI+WhQxTEq2h1QvGjOTWwGxp1ovHH0HEb9KnAzcYrWd6C0tUBnygeGPe8tcw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654678; 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=A55MlTvVA9xM9Udo2f8ierjn04fv0f7X3KcXB2zJzxA=; b=VWovHpgHq77VXv1MgbbOd4qLA/gVso5UjZBmAjxHOx1LaVDpSXX1gV2njJrf1oEWdoFosdgqczwcwQNtuJH73oKGUhQ2dgUmtEAmMfbnrjS6ye/kRs0khWCpCVNuNJIGuQdxrLif+BhYRIhUEsUq4naWv9u2lhhbXlkrUtp7tjg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654678409363.11901729319015; Wed, 11 Jun 2025 08:11:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN3A-0005vu-2Y; Wed, 11 Jun 2025 11:07:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN31-0005cG-0E for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:28 -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 1uPN2y-0007Bf-FY for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:25 -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-306-kiC5NFLnN9KcCvOnFBQv-g-1; Wed, 11 Jun 2025 11:07:17 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 BBDD1180047F; Wed, 11 Jun 2025 15:07:16 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 261B0180045B; Wed, 11 Jun 2025 15:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654443; 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=A55MlTvVA9xM9Udo2f8ierjn04fv0f7X3KcXB2zJzxA=; b=JRsnqpr0vUhsXnu6mJz2WggN0aruzgyVKRwnlUKjceq6awT9s5+cQIZpJwJa8zNfp4L+NG zzjF2UDf+/7yCriOsWFXRUSH7dnIcKnCD5/12OF0kKMqMqRvVC+UGTrfeUnXvs7Z1ht0m3 toYjnVynKc882a1vV82uf1+O/oBBgus= X-MC-Unique: kiC5NFLnN9KcCvOnFBQv-g-1 X-Mimecast-MFC-AGG-ID: kiC5NFLnN9KcCvOnFBQv-g_1749654436 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 21/27] vfio/pci: vfio_pci_vector_init Date: Wed, 11 Jun 2025 17:06:13 +0200 Message-ID: <20250611150620.701903-22-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655231452116600 From: Steve Sistare Extract a subroutine vfio_pci_vector_init. No functional change. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-13-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 2da5989581e72538cf61de3f453070b5e4f53cc4..7a33c19ea28c454221ee430784e= 5d84cf498486b 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -531,6 +531,22 @@ static void set_irq_signalling(VFIODevice *vbasedev, V= FIOMSIVector *vector, } } =20 +static void vfio_pci_vector_init(VFIOPCIDevice *vdev, int nr) +{ + VFIOMSIVector *vector =3D &vdev->msi_vectors[nr]; + PCIDevice *pdev =3D &vdev->pdev; + + vector->vdev =3D vdev; + vector->virq =3D -1; + if (event_notifier_init(&vector->interrupt, 0)) { + error_report("vfio: Error: event_notifier_init failed"); + } + vector->use =3D true; + if (vdev->interrupt =3D=3D VFIO_INT_MSIX) { + msix_vector_use(pdev, nr); + } +} + static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr, MSIMessage *msg, IOHandler *handler) { @@ -544,13 +560,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, un= signed int nr, vector =3D &vdev->msi_vectors[nr]; =20 if (!vector->use) { - vector->vdev =3D vdev; - vector->virq =3D -1; - if (event_notifier_init(&vector->interrupt, 0)) { - error_report("vfio: Error: event_notifier_init failed"); - } - vector->use =3D true; - msix_vector_use(pdev, nr); + vfio_pci_vector_init(vdev, nr); } =20 qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654491; cv=none; d=zohomail.com; s=zohoarc; b=XhAweQfWE5uM/TY9Xr7y0LuCi2wO4iJaP+2OwqpsCW2kynhS2vwIMDgZLy0IGQPgWKufpKSP8KOTTohRnbwH78enQqiOeJKn2TD+W7deontIlJAjmtKCg5NzcPFp6p9UKZ+b2wyEItgIpep1W4fIVMjMZksWuOTOZxhr/WxHDH4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654491; 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=7ZCUI4orxnF82b1y3t9R6rH4WLabU1ZdInS/jhGwZkA=; b=IsUPg0gRiQwgOrII1jd/h9QRRQogM4UDmzL8hoyHGxSBcDjjnF2Lm6su6k3kEjfYoTdlf6ccYOuFn+VwUoL09TVkkNWRdlDAn7hgpDBTCjs++7MbqSy6aW2rZiSzm2Ijb8mnl479/pDMdZB2q2afqEWse1XBcGUx4SIkd44jgSk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654491433225.9708201370131; Wed, 11 Jun 2025 08:08:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN3C-00065O-97; Wed, 11 Jun 2025 11:07:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN2z-0005br-Q7 for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:26 -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 1uPN2y-0007BU-29 for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:25 -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-265-zbmHHeWzPhuLxOHFmN8peQ-1; Wed, 11 Jun 2025 11:07:21 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 DD8BB18002ED; Wed, 11 Jun 2025 15:07:18 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 46D65180045B; Wed, 11 Jun 2025 15:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654443; 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=7ZCUI4orxnF82b1y3t9R6rH4WLabU1ZdInS/jhGwZkA=; b=Siede8fzYkyHqx1O2I8OVp/MvKZjkYntwfRmw4Nndp3rXiaJDQEFZ70nqaVoDQQmX3XcW6 ppp1Cg1YFUzeqe+QC1tXFPLA13mxVGYNZpTjb4QNC1e/xSWvqG7weye+XKQJtAbjyKsr3V 8p0Q0kTTejRlczOJ/gcP3jbLU1oHJkQ= X-MC-Unique: zbmHHeWzPhuLxOHFmN8peQ-1 X-Mimecast-MFC-AGG-ID: zbmHHeWzPhuLxOHFmN8peQ_1749654439 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 22/27] vfio/pci: vfio_notifier_init Date: Wed, 11 Jun 2025 17:06:14 +0200 Message-ID: <20250611150620.701903-23-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655048714116600 From: Steve Sistare Move event_notifier_init calls to a helper vfio_notifier_init. This version is trivial, but it will be expanded to support CPR in subsequent patches. No functional change. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-14-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 7a33c19ea28c454221ee430784e5d84cf498486b..dc0d9a7fbb939cdcae58c40e7bd= 33b0a2c1bd3ec 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -57,6 +57,16 @@ static void vfio_disable_interrupts(VFIOPCIDevice *vdev); static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled); static void vfio_msi_disable_common(VFIOPCIDevice *vdev); =20 +static bool vfio_notifier_init(EventNotifier *e, const char *name, Error *= *errp) +{ + int ret =3D event_notifier_init(e, 0); + + if (ret) { + error_setg_errno(errp, -ret, "vfio_notifier_init %s failed", name); + } + return !ret; +} + /* * Disabling BAR mmaping can be slow, but toggling it around INTx can * also be a huge overhead. We try to get the best of both worlds by @@ -137,8 +147,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, E= rror **errp) pci_irq_deassert(&vdev->pdev); =20 /* Get an eventfd for resample/unmask */ - if (event_notifier_init(&vdev->intx.unmask, 0)) { - error_setg(errp, "event_notifier_init failed eoi"); + if (!vfio_notifier_init(&vdev->intx.unmask, "intx-unmask", errp)) { goto fail; } =20 @@ -269,7 +278,6 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error= **errp) uint8_t pin =3D vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1= ); Error *err =3D NULL; int32_t fd; - int ret; =20 =20 if (!pin) { @@ -292,9 +300,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error= **errp) } #endif =20 - ret =3D event_notifier_init(&vdev->intx.interrupt, 0); - if (ret) { - error_setg_errno(errp, -ret, "event_notifier_init failed"); + if (!vfio_notifier_init(&vdev->intx.interrupt, "intx-interrupt", errp)= ) { return false; } fd =3D event_notifier_get_fd(&vdev->intx.interrupt); @@ -474,11 +480,13 @@ static void vfio_add_kvm_msi_virq(VFIOPCIDevice *vdev= , VFIOMSIVector *vector, =20 static void vfio_connect_kvm_msi_virq(VFIOMSIVector *vector) { + const char *name =3D "kvm_interrupt"; + if (vector->virq < 0) { return; } =20 - if (event_notifier_init(&vector->kvm_interrupt, 0)) { + if (!vfio_notifier_init(&vector->kvm_interrupt, name, NULL)) { goto fail_notifier; } =20 @@ -535,11 +543,12 @@ static void vfio_pci_vector_init(VFIOPCIDevice *vdev,= int nr) { VFIOMSIVector *vector =3D &vdev->msi_vectors[nr]; PCIDevice *pdev =3D &vdev->pdev; + Error *err =3D NULL; =20 vector->vdev =3D vdev; vector->virq =3D -1; - if (event_notifier_init(&vector->interrupt, 0)) { - error_report("vfio: Error: event_notifier_init failed"); + if (!vfio_notifier_init(&vector->interrupt, "interrupt", &err)) { + error_report_err(err); } vector->use =3D true; if (vdev->interrupt =3D=3D VFIO_INT_MSIX) { @@ -755,13 +764,14 @@ retry: =20 for (i =3D 0; i < vdev->nr_vectors; i++) { VFIOMSIVector *vector =3D &vdev->msi_vectors[i]; + Error *err =3D NULL; =20 vector->vdev =3D vdev; vector->virq =3D -1; vector->use =3D true; =20 - if (event_notifier_init(&vector->interrupt, 0)) { - error_report("vfio: Error: event_notifier_init failed"); + if (!vfio_notifier_init(&vector->interrupt, "interrupt", &err)) { + error_report_err(err); } =20 qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), @@ -2928,8 +2938,8 @@ void vfio_pci_register_err_notifier(VFIOPCIDevice *vd= ev) return; } =20 - if (event_notifier_init(&vdev->err_notifier, 0)) { - error_report("vfio: Unable to init event notifier for error detect= ion"); + if (!vfio_notifier_init(&vdev->err_notifier, "err_notifier", &err)) { + error_report_err(err); vdev->pci_aer =3D false; return; } @@ -2995,8 +3005,8 @@ void vfio_pci_register_req_notifier(VFIOPCIDevice *vd= ev) return; } =20 - if (event_notifier_init(&vdev->req_notifier, 0)) { - error_report("vfio: Unable to init event notifier for device reque= st"); + if (!vfio_notifier_init(&vdev->req_notifier, "req_notifier", &err)) { + error_report_err(err); return; } =20 --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654645; cv=none; d=zohomail.com; s=zohoarc; b=lQHJOFO8XRusLKSZSIInPFWl61CsQaCBdOYRkLbZRK91g7FegE3C/zAhU4nxwHComXYDG+vypvEbF5kawwHsqN1+FsgwgrY2LNKxPCf0/NX6N6mvZQ62Rn0MDNg25xA6PrldG1CbzdswIKmm3xt6pBN3zQUziL2haA9lnKkym8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654645; 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=gOQzLLiN8iauOujs8Nfw0zuPWkL6ghzAGZLmzgYRxsA=; b=axixzFRO4GC+K0S7JVi5/wUMCebbs5f87RbkA8doy5C65Uwy73+JqMs3PFGWRMI50RH56hAVOPLoSHT6t+RLi5Wka5puYGR+MY14T5xcyedSvH8bJag2QRGReKMbmAwl40XAk0PgnqdtNZDf4S3Z9mWJ0RLifu8YZFdU2dkVORQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17496546459131022.4068712713043; Wed, 11 Jun 2025 08:10:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN3C-00065P-7J; Wed, 11 Jun 2025 11:07:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN31-0005cP-5r for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:28 -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 1uPN2y-0007Bl-Tt for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:26 -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-38-h_JtNDq_PxaZAZX1-jREKg-1; Wed, 11 Jun 2025 11:07:21 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 0BED819560B4; Wed, 11 Jun 2025 15:07:21 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 678EA180045B; Wed, 11 Jun 2025 15:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654444; 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=gOQzLLiN8iauOujs8Nfw0zuPWkL6ghzAGZLmzgYRxsA=; b=DlSpxnczfir1Sl+PMDUOJOno3BStgN5ufWoqqpitCDHcIJsRjoVruqrHAkoRHBGxF27+eb 3L5ZD8ejKqvknImePBuDywhxjrAuLlIWFlktIwI/oFUQsHeK+xStrQEz3hMIfFJgIcEpL7 8r/XnvBT5HHRG22gnfRFjvtl/DbNnuM= X-MC-Unique: h_JtNDq_PxaZAZX1-jREKg-1 X-Mimecast-MFC-AGG-ID: h_JtNDq_PxaZAZX1-jREKg_1749654441 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 23/27] vfio/pci: pass vector to virq functions Date: Wed, 11 Jun 2025 17:06:15 +0200 Message-ID: <20250611150620.701903-24-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655204776116600 From: Steve Sistare Pass the vector number to vfio_connect_kvm_msi_virq and vfio_remove_kvm_msi_virq, so it can be passed to their subroutines in a subsequent patch. No functional change. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-15-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index dc0d9a7fbb939cdcae58c40e7bd33b0a2c1bd3ec..1d22c41efb6c6150ca1dff6ace7= 52faad4a0fcfd 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -478,7 +478,7 @@ static void vfio_add_kvm_msi_virq(VFIOPCIDevice *vdev, = VFIOMSIVector *vector, vector_n, &vdev->pdev); } =20 -static void vfio_connect_kvm_msi_virq(VFIOMSIVector *vector) +static void vfio_connect_kvm_msi_virq(VFIOMSIVector *vector, int nr) { const char *name =3D "kvm_interrupt"; =20 @@ -504,7 +504,8 @@ fail_notifier: vector->virq =3D -1; } =20 -static void vfio_remove_kvm_msi_virq(VFIOMSIVector *vector) +static void vfio_remove_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *v= ector, + int nr) { kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vector->kvm_interrup= t, vector->virq); @@ -581,7 +582,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, uns= igned int nr, */ if (vector->virq >=3D 0) { if (!msg) { - vfio_remove_kvm_msi_virq(vector); + vfio_remove_kvm_msi_virq(vdev, vector, nr); } else { vfio_update_kvm_msi_virq(vector, *msg, pdev); } @@ -593,7 +594,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, uns= igned int nr, vfio_route_change =3D kvm_irqchip_begin_route_changes(kvm_= state); vfio_add_kvm_msi_virq(vdev, vector, nr, true); kvm_irqchip_commit_route_changes(&vfio_route_change); - vfio_connect_kvm_msi_virq(vector); + vfio_connect_kvm_msi_virq(vector, nr); } } } @@ -687,7 +688,7 @@ static void vfio_commit_kvm_msi_virq_batch(VFIOPCIDevic= e *vdev) kvm_irqchip_commit_route_changes(&vfio_route_change); =20 for (i =3D 0; i < vdev->nr_vectors; i++) { - vfio_connect_kvm_msi_virq(&vdev->msi_vectors[i]); + vfio_connect_kvm_msi_virq(&vdev->msi_vectors[i], i); } } =20 @@ -827,7 +828,7 @@ static void vfio_msi_disable_common(VFIOPCIDevice *vdev) VFIOMSIVector *vector =3D &vdev->msi_vectors[i]; if (vdev->msi_vectors[i].use) { if (vector->virq >=3D 0) { - vfio_remove_kvm_msi_virq(vector); + vfio_remove_kvm_msi_virq(vdev, vector, i); } qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), NULL, NULL, NULL); --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654716; cv=none; d=zohomail.com; s=zohoarc; b=JbVtLIKAMei9ro+0MJsqbV10uBUKwkWnhi0fB8vKEkROA1HDvbbjB3srUthcqiGmN3M5f4zMtiR5fV8Mwsna08diU5reBf+/ecgTVwVae1SJRFE6Y6AUgTWOPaV2DnVyRLYnXM4YSQyMYHRpfTn8yW1a/zn4Ix1bNNw1x0nZzU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654716; 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=lG8a96YdjQCH9XXM3WHbjpwIIIH7Gvf8mUYoPYWvZsY=; b=mqvQ+3OJ8tjR6Y1O0poJpbnGyl0BDG4K6f9z4kA8yXifLmBTh3HCcbgWSGlCyW999cmcdXvwZuSZFycD946i77w35ri6nU9X0Y9hy7aG/o96MGmtcOGW+3k++HpncZ+8OcDgy1HIdfjwWNAxRAKlqpRmNxNy5qf3i9lHckqNKq0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654716858505.7663134346943; Wed, 11 Jun 2025 08:11:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN3A-0005w1-2m; Wed, 11 Jun 2025 11:07:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN32-0005cg-JS for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:28 -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 1uPN30-0007By-Pj for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:28 -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-184---Ks2alsPe69cqT20_j27g-1; Wed, 11 Jun 2025 11:07:24 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 49D5D1956080; Wed, 11 Jun 2025 15:07:23 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 87478180045B; Wed, 11 Jun 2025 15:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654445; 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=lG8a96YdjQCH9XXM3WHbjpwIIIH7Gvf8mUYoPYWvZsY=; b=BKZxXEeTgz9B+WapTADH9VhpcxHr4sZ7l4CVngbgkvTisgiZX69LHZgn/F5I/NFC0GnrX2 4lvOYUXWFi+E5KrG4zyLg8//cjyul1gV2q7ml5NmMKxaQMr5hlWVA/nPjpDVHXiyiQbIoS GXGJY3Dmpf79vIum7H0xBKMXmd34Ljk= X-MC-Unique: --Ks2alsPe69cqT20_j27g-1 X-Mimecast-MFC-AGG-ID: --Ks2alsPe69cqT20_j27g_1749654443 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 24/27] vfio/pci: vfio_notifier_init cpr parameters Date: Wed, 11 Jun 2025 17:06:16 +0200 Message-ID: <20250611150620.701903-25-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655265772116600 From: Steve Sistare Pass vdev and nr to vfio_notifier_init, for use by CPR in a subsequent patch. No functional change. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-16-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 1d22c41efb6c6150ca1dff6ace752faad4a0fcfd..9ee36da626c319b166cab3d6348= 42e28d4d58e10 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -57,7 +57,8 @@ static void vfio_disable_interrupts(VFIOPCIDevice *vdev); static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled); static void vfio_msi_disable_common(VFIOPCIDevice *vdev); =20 -static bool vfio_notifier_init(EventNotifier *e, const char *name, Error *= *errp) +static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e, + const char *name, int nr, Error **errp) { int ret =3D event_notifier_init(e, 0); =20 @@ -147,7 +148,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, E= rror **errp) pci_irq_deassert(&vdev->pdev); =20 /* Get an eventfd for resample/unmask */ - if (!vfio_notifier_init(&vdev->intx.unmask, "intx-unmask", errp)) { + if (!vfio_notifier_init(vdev, &vdev->intx.unmask, "intx-unmask", 0, er= rp)) { goto fail; } =20 @@ -300,7 +301,8 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error= **errp) } #endif =20 - if (!vfio_notifier_init(&vdev->intx.interrupt, "intx-interrupt", errp)= ) { + if (!vfio_notifier_init(vdev, &vdev->intx.interrupt, "intx-interrupt",= 0, + errp)) { return false; } fd =3D event_notifier_get_fd(&vdev->intx.interrupt); @@ -486,7 +488,8 @@ static void vfio_connect_kvm_msi_virq(VFIOMSIVector *ve= ctor, int nr) return; } =20 - if (!vfio_notifier_init(&vector->kvm_interrupt, name, NULL)) { + if (!vfio_notifier_init(vector->vdev, &vector->kvm_interrupt, name, nr, + NULL)) { goto fail_notifier; } =20 @@ -544,12 +547,13 @@ static void vfio_pci_vector_init(VFIOPCIDevice *vdev,= int nr) { VFIOMSIVector *vector =3D &vdev->msi_vectors[nr]; PCIDevice *pdev =3D &vdev->pdev; - Error *err =3D NULL; + Error *local_err =3D NULL; =20 vector->vdev =3D vdev; vector->virq =3D -1; - if (!vfio_notifier_init(&vector->interrupt, "interrupt", &err)) { - error_report_err(err); + if (!vfio_notifier_init(vdev, &vector->interrupt, "interrupt", nr, + &local_err)) { + error_report_err(local_err); } vector->use =3D true; if (vdev->interrupt =3D=3D VFIO_INT_MSIX) { @@ -765,14 +769,15 @@ retry: =20 for (i =3D 0; i < vdev->nr_vectors; i++) { VFIOMSIVector *vector =3D &vdev->msi_vectors[i]; - Error *err =3D NULL; + Error *local_err =3D NULL; =20 vector->vdev =3D vdev; vector->virq =3D -1; vector->use =3D true; =20 - if (!vfio_notifier_init(&vector->interrupt, "interrupt", &err)) { - error_report_err(err); + if (!vfio_notifier_init(vdev, &vector->interrupt, "interrupt", i, + &local_err)) { + error_report_err(local_err); } =20 qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), @@ -2939,7 +2944,8 @@ void vfio_pci_register_err_notifier(VFIOPCIDevice *vd= ev) return; } =20 - if (!vfio_notifier_init(&vdev->err_notifier, "err_notifier", &err)) { + if (!vfio_notifier_init(vdev, &vdev->err_notifier, "err_notifier", 0, + &err)) { error_report_err(err); vdev->pci_aer =3D false; return; @@ -3006,7 +3012,8 @@ void vfio_pci_register_req_notifier(VFIOPCIDevice *vd= ev) return; } =20 - if (!vfio_notifier_init(&vdev->req_notifier, "req_notifier", &err)) { + if (!vfio_notifier_init(vdev, &vdev->req_notifier, "req_notifier", 0, + &err)) { error_report_err(err); return; } --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654706; cv=none; d=zohomail.com; s=zohoarc; b=D4Rx8JEY196FMWO51Nwg5gZ7tQLZJSxAV7QuYlhRMyKSpsK9JL4S4rKzHYURaFAdqTjoi0ZZQfkH8JGvWpC3gk41X6TYryWknOB303PGx5FDddj4oBt74JEYvuA6f8Hi3Vz1dYua+vdbClwRqiFzeStNDIC2vJ5hvMEdec6+a9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654706; 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=pA9yFQZH+vk+flaeoJJGabmz2TfQN/RwC81Uw0R9Sds=; b=QdEqlxze+VXeOhmihn6QaEWh7z9ojr2kEygkh43GQ4AGw5CfjbQPqcY2sT0qgBxp5/JqZ6oWQVjEj+7QbIQoBq0/Vq5fMOanbiDE8Mn50Oja8ZYVOmv+CmroTJu8SyJSz3owDgsJccUif/2jtOi++l40MSP1EJ0p4XLdZtyaDwI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654706649116.7779438082514; Wed, 11 Jun 2025 08:11:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN3A-0005ya-Li; Wed, 11 Jun 2025 11:07:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN38-0005ny-GC for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:34 -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 1uPN36-0007Cw-7M for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:33 -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-478-FJ3XCkDDOyOsNrmusjabzA-1; Wed, 11 Jun 2025 11:07:26 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 48B4818089B5; Wed, 11 Jun 2025 15:07:25 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A7782180045C; Wed, 11 Jun 2025 15:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654451; 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=pA9yFQZH+vk+flaeoJJGabmz2TfQN/RwC81Uw0R9Sds=; b=BifCbG07Rf124MVDKqsKpX9p6QgIds5fbOUfcREmmQQL2hvVOgoJKmRzo0wYCrp4TB7NQv L4zxk7d/39Mv9rGsPk30tAYbfGB2ejI1ELOh6yax7yE8+Zn9wJsBlekmQTPefWlc2Z1TYZ I8kGpBsmv3GBqrISa7LHkRPpjhzvAtk= X-MC-Unique: FJ3XCkDDOyOsNrmusjabzA-1 X-Mimecast-MFC-AGG-ID: FJ3XCkDDOyOsNrmusjabzA_1749654445 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 25/27] vfio/pci: vfio_notifier_cleanup Date: Wed, 11 Jun 2025 17:06:17 +0200 Message-ID: <20250611150620.701903-26-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655254835116600 From: Steve Sistare Move event_notifier_cleanup calls to a helper vfio_notifier_cleanup. This version is trivial, and does not yet use the vdev and nr parameters. No functional change. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-17-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 9ee36da626c319b166cab3d634842e28d4d58e10..06a7a63cf501deafe26b1a9172e= b56fecf4deaf3 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -68,6 +68,12 @@ static bool vfio_notifier_init(VFIOPCIDevice *vdev, Even= tNotifier *e, return !ret; } =20 +static void vfio_notifier_cleanup(VFIOPCIDevice *vdev, EventNotifier *e, + const char *name, int nr) +{ + event_notifier_cleanup(e); +} + /* * Disabling BAR mmaping can be slow, but toggling it around INTx can * also be a huge overhead. We try to get the best of both worlds by @@ -180,7 +186,7 @@ fail_vfio: kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vdev->intx.interrupt, vdev->intx.route.irq); fail_irqfd: - event_notifier_cleanup(&vdev->intx.unmask); + vfio_notifier_cleanup(vdev, &vdev->intx.unmask, "intx-unmask", 0); fail: qemu_set_fd_handler(irq_fd, vfio_intx_interrupt, NULL, vdev); vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); @@ -212,7 +218,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) } =20 /* We only need to close the eventfd for VFIO to cleanup the kernel si= de */ - event_notifier_cleanup(&vdev->intx.unmask); + vfio_notifier_cleanup(vdev, &vdev->intx.unmask, "intx-unmask", 0); =20 /* QEMU starts listening for interrupt events. */ qemu_set_fd_handler(event_notifier_get_fd(&vdev->intx.interrupt), @@ -311,7 +317,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error= **errp) if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_= INDEX, 0, VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { qemu_set_fd_handler(fd, NULL, NULL, vdev); - event_notifier_cleanup(&vdev->intx.interrupt); + vfio_notifier_cleanup(vdev, &vdev->intx.interrupt, "intx-interrupt= ", 0); return false; } =20 @@ -338,7 +344,7 @@ static void vfio_intx_disable(VFIOPCIDevice *vdev) =20 fd =3D event_notifier_get_fd(&vdev->intx.interrupt); qemu_set_fd_handler(fd, NULL, NULL, vdev); - event_notifier_cleanup(&vdev->intx.interrupt); + vfio_notifier_cleanup(vdev, &vdev->intx.interrupt, "intx-interrupt", 0= ); =20 vdev->interrupt =3D VFIO_INT_NONE; =20 @@ -501,7 +507,7 @@ static void vfio_connect_kvm_msi_virq(VFIOMSIVector *ve= ctor, int nr) return; =20 fail_kvm: - event_notifier_cleanup(&vector->kvm_interrupt); + vfio_notifier_cleanup(vector->vdev, &vector->kvm_interrupt, name, nr); fail_notifier: kvm_irqchip_release_virq(kvm_state, vector->virq); vector->virq =3D -1; @@ -514,7 +520,7 @@ static void vfio_remove_kvm_msi_virq(VFIOPCIDevice *vde= v, VFIOMSIVector *vector, vector->virq); kvm_irqchip_release_virq(kvm_state, vector->virq); vector->virq =3D -1; - event_notifier_cleanup(&vector->kvm_interrupt); + vfio_notifier_cleanup(vdev, &vector->kvm_interrupt, "kvm_interrupt", n= r); } =20 static void vfio_update_kvm_msi_virq(VFIOMSIVector *vector, MSIMessage msg, @@ -837,7 +843,7 @@ static void vfio_msi_disable_common(VFIOPCIDevice *vdev) } qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), NULL, NULL, NULL); - event_notifier_cleanup(&vector->interrupt); + vfio_notifier_cleanup(vdev, &vector->interrupt, "interrupt", i= ); } } =20 @@ -2958,7 +2964,7 @@ void vfio_pci_register_err_notifier(VFIOPCIDevice *vd= ev) VFIO_IRQ_SET_ACTION_TRIGGER, fd, &e= rr)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); qemu_set_fd_handler(fd, NULL, NULL, vdev); - event_notifier_cleanup(&vdev->err_notifier); + vfio_notifier_cleanup(vdev, &vdev->err_notifier, "err_notifier", 0= ); vdev->pci_aer =3D false; } } @@ -2977,7 +2983,7 @@ static void vfio_unregister_err_notifier(VFIOPCIDevic= e *vdev) } qemu_set_fd_handler(event_notifier_get_fd(&vdev->err_notifier), NULL, NULL, vdev); - event_notifier_cleanup(&vdev->err_notifier); + vfio_notifier_cleanup(vdev, &vdev->err_notifier, "err_notifier", 0); } =20 static void vfio_req_notifier_handler(void *opaque) @@ -3025,7 +3031,7 @@ void vfio_pci_register_req_notifier(VFIOPCIDevice *vd= ev) VFIO_IRQ_SET_ACTION_TRIGGER, fd, &e= rr)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); qemu_set_fd_handler(fd, NULL, NULL, vdev); - event_notifier_cleanup(&vdev->req_notifier); + vfio_notifier_cleanup(vdev, &vdev->req_notifier, "req_notifier", 0= ); } else { vdev->req_enabled =3D true; } @@ -3045,7 +3051,7 @@ static void vfio_unregister_req_notifier(VFIOPCIDevic= e *vdev) } qemu_set_fd_handler(event_notifier_get_fd(&vdev->req_notifier), NULL, NULL, vdev); - event_notifier_cleanup(&vdev->req_notifier); + vfio_notifier_cleanup(vdev, &vdev->req_notifier, "req_notifier", 0); =20 vdev->req_enabled =3D false; } --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654486; cv=none; d=zohomail.com; s=zohoarc; b=H5oqE0D+zH62osTE9k0yrwZpeSdW25EtXR5XKJMBHFYF5xp/UfRQJrLxGLEDikFLl4pLZ/Azwfne80Y0dWObDTvG0cXAFuliqFQz932c+SGWwBGqhK4aG5KJGwn17/EmgMPT08uIC49X9qUpY/87Z0gkHaFYVgrX8SkbtkDXO0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654486; 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=4BsxD0QoGu2gGa5vU6B8722YrthlSDcy7GlRoSTzSQ8=; b=GDMz+D81yOC+gQ2Q2l/AZBktJGvZxsK2w+JA7GLYiaqLiU6SF3oBilOB00GoGtN8nJwJ0xsMN2GqWFwKsEZRRIc3Jmt6enqdbtX+V80c6VkfjbgHuDvGk8q6hGhQNM+TiedcIY8fIQdfRe3NNknouwG/VDCf6Pjvn3O/rlbOSvs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654486085253.69134769900154; Wed, 11 Jun 2025 08:08:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN3F-0006Tm-Eh; Wed, 11 Jun 2025 11:07:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN3C-00067h-DQ for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:38 -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 1uPN3A-0007DZ-Ch for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:38 -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-287-4vN196XcPsydvL1BwnItZA-1; Wed, 11 Jun 2025 11:07:29 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 66F43180028E; Wed, 11 Jun 2025 15:07:27 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C651818002B6; Wed, 11 Jun 2025 15:07:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654455; 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=4BsxD0QoGu2gGa5vU6B8722YrthlSDcy7GlRoSTzSQ8=; b=OdHbjHQtuoUOUwc1vQND4aBtF207ISsG8m0CBi325huBBDP5GDWOaAGf8Ibt070WROKLGq du9RzfT1BiFqUH5EJXowlLQZzGY8ApS7kUKqWm1nnWhwNcI8cbj+oOwDPoLrbV5BxNOGBx Y4bDWBcGP8CCoT3eAVbHddcgfS/hHN4= X-MC-Unique: 4vN196XcPsydvL1BwnItZA-1 X-Mimecast-MFC-AGG-ID: 4vN196XcPsydvL1BwnItZA_1749654447 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 26/27] vfio/pci: export MSI functions Date: Wed, 11 Jun 2025 17:06:18 +0200 Message-ID: <20250611150620.701903-27-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749654997877116600 From: Steve Sistare Export various MSI functions, renamed with a vfio_pci prefix, for use by CPR in subsequent patches. No functional change. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1749569991-25171-18-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 8 ++++++++ hw/vfio/pci.c | 29 +++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index d4c6b2e7b77f26e44f902e6b840d7e39d39de3e9..d3dc2274a97bc591b02df117f44= 88d24cd39fe7a 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -210,6 +210,14 @@ static inline bool vfio_is_vga(VFIOPCIDevice *vdev) return class =3D=3D PCI_CLASS_DISPLAY_VGA; } =20 +/* MSI/MSI-X/INTx */ +void vfio_pci_vector_init(VFIOPCIDevice *vdev, int nr); +void vfio_pci_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vector, + int vector_n, bool msix); +void vfio_pci_prepare_kvm_msi_virq_batch(VFIOPCIDevice *vdev); +void vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev); +bool vfio_pci_intx_enable(VFIOPCIDevice *vdev, Error **errp); + uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len); void vfio_pci_write_config(PCIDevice *pdev, uint32_t addr, uint32_t val, int len); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 06a7a63cf501deafe26b1a9172eb56fecf4deaf3..fa25bded25c51f8efb6c5ad31bd= 90506cd69745c 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -351,6 +351,11 @@ static void vfio_intx_disable(VFIOPCIDevice *vdev) trace_vfio_intx_disable(vdev->vbasedev.name); } =20 +bool vfio_pci_intx_enable(VFIOPCIDevice *vdev, Error **errp) +{ + return vfio_intx_enable(vdev, errp); +} + /* * MSI/X */ @@ -475,8 +480,8 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, boo= l msix) return ret; } =20 -static void vfio_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vect= or, - int vector_n, bool msix) +void vfio_pci_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vector, + int vector_n, bool msix) { if ((msix && vdev->no_kvm_msix) || (!msix && vdev->no_kvm_msi)) { return; @@ -549,7 +554,7 @@ static void set_irq_signalling(VFIODevice *vbasedev, VF= IOMSIVector *vector, } } =20 -static void vfio_pci_vector_init(VFIOPCIDevice *vdev, int nr) +void vfio_pci_vector_init(VFIOPCIDevice *vdev, int nr) { VFIOMSIVector *vector =3D &vdev->msi_vectors[nr]; PCIDevice *pdev =3D &vdev->pdev; @@ -599,10 +604,10 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, u= nsigned int nr, } else { if (msg) { if (vdev->defer_kvm_irq_routing) { - vfio_add_kvm_msi_virq(vdev, vector, nr, true); + vfio_pci_add_kvm_msi_virq(vdev, vector, nr, true); } else { vfio_route_change =3D kvm_irqchip_begin_route_changes(kvm_= state); - vfio_add_kvm_msi_virq(vdev, vector, nr, true); + vfio_pci_add_kvm_msi_virq(vdev, vector, nr, true); kvm_irqchip_commit_route_changes(&vfio_route_change); vfio_connect_kvm_msi_virq(vector, nr); } @@ -681,14 +686,14 @@ static void vfio_msix_vector_release(PCIDevice *pdev,= unsigned int nr) } } =20 -static void vfio_prepare_kvm_msi_virq_batch(VFIOPCIDevice *vdev) +void vfio_pci_prepare_kvm_msi_virq_batch(VFIOPCIDevice *vdev) { assert(!vdev->defer_kvm_irq_routing); vdev->defer_kvm_irq_routing =3D true; vfio_route_change =3D kvm_irqchip_begin_route_changes(kvm_state); } =20 -static void vfio_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev) +void vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev) { int i; =20 @@ -718,14 +723,14 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev) * routes once rather than per vector provides a substantial * performance improvement. */ - vfio_prepare_kvm_msi_virq_batch(vdev); + vfio_pci_prepare_kvm_msi_virq_batch(vdev); =20 if (msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use, vfio_msix_vector_release, NULL)) { error_report("vfio: msix_set_vector_notifiers failed"); } =20 - vfio_commit_kvm_msi_virq_batch(vdev); + vfio_pci_commit_kvm_msi_virq_batch(vdev); =20 if (vdev->nr_vectors) { ret =3D vfio_enable_vectors(vdev, true); @@ -769,7 +774,7 @@ retry: * Deferring to commit the KVM routes once rather than per vector * provides a substantial performance improvement. */ - vfio_prepare_kvm_msi_virq_batch(vdev); + vfio_pci_prepare_kvm_msi_virq_batch(vdev); =20 vdev->msi_vectors =3D g_new0(VFIOMSIVector, vdev->nr_vectors); =20 @@ -793,10 +798,10 @@ retry: * Attempt to enable route through KVM irqchip, * default to userspace handling if unavailable. */ - vfio_add_kvm_msi_virq(vdev, vector, i, false); + vfio_pci_add_kvm_msi_virq(vdev, vector, i, false); } =20 - vfio_commit_kvm_msi_virq_batch(vdev); + vfio_pci_commit_kvm_msi_virq_batch(vdev); =20 /* Set interrupt type prior to possible interrupts */ vdev->interrupt =3D VFIO_INT_MSI; --=20 2.49.0 From nobody Sat Nov 15 16:07:32 2025 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=1749654679; cv=none; d=zohomail.com; s=zohoarc; b=C5CxCT2jABjhcPwcQlkHAoEkwGrJQ7rh2C1wCNmiG6njF6w4TV9mCbrFFwhDp1vhcBTlNbpoZl186cNSgGF749KQVky9NrDq14x/ObaHFA2Drs7GyVFk61JIpqgKN36tWiTrHYKflCkC+/p6JaYhphAhhEs/YuGiiBghixKzQfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749654679; 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=kFq26DYsWLmzPImzHrGHSPD9KDvKkjwHURprqDjb7nI=; b=QJm3jzjPcNzQQI32PX6Eh61r+U0p7ZGSiGrTQKR+Gs5IQ6qiZWrKN334ctdciqt4XD3P1VhlcTbRRrmhLCXDGCGxwkyxMqw26YIbNe1QC6HXgvgkc7JXZfD2onC3fopzvB7r5VPB7Uc0uMEQwMAxxFUHERV932zGAV8tmqLM75E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749654679842703.8297280838245; Wed, 11 Jun 2025 08:11:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPN3D-0006Gk-MT; Wed, 11 Jun 2025 11:07:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPN3A-0005zR-MX for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:36 -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 1uPN38-0007DL-RQ for qemu-devel@nongnu.org; Wed, 11 Jun 2025 11:07:36 -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-509-ik5SPssXNCWP2hS7YfhWdQ-1; Wed, 11 Jun 2025 11:07:30 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 A4BF11801BD8; Wed, 11 Jun 2025 15:07:29 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.225.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E524E180045B; Wed, 11 Jun 2025 15:07:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749654453; 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=kFq26DYsWLmzPImzHrGHSPD9KDvKkjwHURprqDjb7nI=; b=YrVwhwtPSttFmCSfPobqDyuVCcJAeqrJTivcv7vYBY69ChUjyks4stHyDSo/tJY2L8hrvT LXqe4hZnt80ZCreJPmO+IlFgDRMMSM9TCwDBDupPMmNyJr7mh7R9vIk9EYc30O5Zyl/ksU tL34/HsefeVhBY1q8X0DR9Gkijt1UCY= X-MC-Unique: ik5SPssXNCWP2hS7YfhWdQ-1 X-Mimecast-MFC-AGG-ID: ik5SPssXNCWP2hS7YfhWdQ_1749654449 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 27/27] vfio: improve VFIODeviceIOOps docs Date: Wed, 11 Jun 2025 17:06:19 +0200 Message-ID: <20250611150620.701903-28-clg@redhat.com> In-Reply-To: <20250611150620.701903-1-clg@redhat.com> References: <20250611150620.701903-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749655236110116600 From: John Levon Explicitly describe every parameter rather than summarizing. Signed-off-by: John Levon Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250611104753.1199796-1-john.levo= n@nutanix.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-device.h | 52 +++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index f39259406bdd7b4577c4c54cfb3ac0dbbcedccb2..d45e5a68a24e7990fa93ce6549f= 5710b4f25a037 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -168,14 +168,25 @@ struct VFIODeviceIOOps { * @device_feature * * Fill in feature info for the given device. + * + * @vdev: #VFIODevice to use + * @feat: feature information to fill in + * + * Returns 0 on success or -errno. */ - int (*device_feature)(VFIODevice *vdev, struct vfio_device_feature *); + int (*device_feature)(VFIODevice *vdev, struct vfio_device_feature *fe= at); =20 /** * @get_region_info * - * Fill in @info (and optionally @fd) with information on the region g= iven - * by @info->index. + * Get the information for a given region on the device. + * + * @vdev: #VFIODevice to use + * @info: set @info->index to the region index to look up; the rest of= the + * struct will be filled in on success + * @fd: pointer to the fd for the region; will be -1 if not found + * + * Returns 0 on success or -errno. */ int (*get_region_info)(VFIODevice *vdev, struct vfio_region_info *info, int *fd); @@ -183,22 +194,38 @@ struct VFIODeviceIOOps { /** * @get_irq_info * - * Fill in @irq with information on the IRQ given by @info->index. + * @vdev: #VFIODevice to use + * @irq: set @irq->index to the IRQ index to look up; the rest of the = struct + * will be filled in on success + * + * Returns 0 on success or -errno. */ int (*get_irq_info)(VFIODevice *vdev, struct vfio_irq_info *irq); =20 /** * @set_irqs * - * Configure IRQs as defined by @irqs. + * Configure IRQs. + * + * @vdev: #VFIODevice to use + * @irqs: IRQ configuration as defined by VFIO docs. + * + * Returns 0 on success or -errno. */ int (*set_irqs)(VFIODevice *vdev, struct vfio_irq_set *irqs); =20 /** * @region_read * - * Read @size bytes from the region @nr at offset @off into the buffer - * @data. + * Read part of a region. + * + * @vdev: #VFIODevice to use + * @nr: region index + * @off: offset within the region + * @size: size in bytes to read + * @data: buffer to read into + * + * Returns number of bytes read on success or -errno. */ int (*region_read)(VFIODevice *vdev, uint8_t nr, off_t off, uint32_t s= ize, void *data); @@ -206,8 +233,15 @@ struct VFIODeviceIOOps { /** * @region_write * - * Write @size bytes to the region @nr at offset @off from the buffer - * @data; if @post, the write is posted. + * Write part of a region. + * + * @vdev: #VFIODevice to use + * @nr: region index + * @off: offset within the region + * @size: size in bytes to write + * @data: buffer to write from + * + * Returns number of bytes write on success or -errno. */ int (*region_write)(VFIODevice *vdev, uint8_t nr, off_t off, uint32_t = size, void *data, bool post); --=20 2.49.0