From nobody Tue May 7 14:26:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631167688111205.98173858325117; Wed, 8 Sep 2021 23:08:08 -0700 (PDT) Received: from localhost ([::1]:50266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mODEF-0006yC-4V for importer@patchew.org; Thu, 09 Sep 2021 02:08:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCj-0004C3-NG for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:33 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2109) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCe-000655-QF for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:33 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H4pLf6S7nzQv5n; Thu, 9 Sep 2021 14:02:18 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:20 +0800 Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:17 +0800 From: "Longpeng(Mike)" To: , , Subject: [PATCH v2 1/9] vfio: simplify the conditional statements in vfio_msi_enable Date: Thu, 9 Sep 2021 14:06:05 +0800 Message-ID: <20210909060613.2815-2-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20210909060613.2815-1-longpeng2@huawei.com> References: <20210909060613.2815-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected 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=45.249.212.188; envelope-from=longpeng2@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chenjiashang@huawei.com, mst@redhat.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, "Longpeng\(Mike\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631167690298100001 Content-Type: text/plain; charset="utf-8" It's unnecessary to test against the specific return value of VFIO_DEVICE_SET_IRQS, since any positive return is an error indicating the number of vectors we should retry with. Signed-off-by: Longpeng(Mike) --- hw/vfio/pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index e1ea1d8..f7a3a13 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -650,7 +650,7 @@ retry: if (ret) { if (ret < 0) { error_report("vfio: Error: Failed to setup MSI fds: %m"); - } else if (ret !=3D vdev->nr_vectors) { + } else { error_report("vfio: Error: Failed to enable %d " "MSI vectors, retry with %d", vdev->nr_vectors, r= et); } @@ -668,7 +668,7 @@ retry: g_free(vdev->msi_vectors); vdev->msi_vectors =3D NULL; =20 - if (ret > 0 && ret !=3D vdev->nr_vectors) { + if (ret > 0) { vdev->nr_vectors =3D ret; goto retry; } --=20 1.8.3.1 From nobody Tue May 7 14:26:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631167804903644.3697355367323; Wed, 8 Sep 2021 23:10:04 -0700 (PDT) Received: from localhost ([::1]:56754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mODG7-0002vD-TV for importer@patchew.org; Thu, 09 Sep 2021 02:10:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCi-0004AC-PX for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:32 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2919) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCe-000654-QN for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:32 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H4pLg1KR6zbmKj; Thu, 9 Sep 2021 14:02:19 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:20 +0800 Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:17 +0800 From: "Longpeng(Mike)" To: , , Subject: [PATCH v2 2/9] vfio: move re-enabling INTX out of the common helper Date: Thu, 9 Sep 2021 14:06:06 +0800 Message-ID: <20210909060613.2815-3-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20210909060613.2815-1-longpeng2@huawei.com> References: <20210909060613.2815-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected 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=45.249.212.187; envelope-from=longpeng2@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chenjiashang@huawei.com, mst@redhat.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, "Longpeng\(Mike\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631167807020100001 Content-Type: text/plain; charset="utf-8" Move re-enabling INTX out, and the callers should decide to re-enable it or not. Signed-off-by: Longpeng(Mike) --- hw/vfio/pci.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index f7a3a13..1e6797f 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -690,7 +690,6 @@ retry: =20 static void vfio_msi_disable_common(VFIOPCIDevice *vdev) { - Error *err =3D NULL; int i; =20 for (i =3D 0; i < vdev->nr_vectors; i++) { @@ -709,15 +708,11 @@ static void vfio_msi_disable_common(VFIOPCIDevice *vd= ev) vdev->msi_vectors =3D NULL; vdev->nr_vectors =3D 0; vdev->interrupt =3D VFIO_INT_NONE; - - vfio_intx_enable(vdev, &err); - if (err) { - error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); - } } =20 static void vfio_msix_disable(VFIOPCIDevice *vdev) { + Error *err =3D NULL; int i; =20 msix_unset_vector_notifiers(&vdev->pdev); @@ -738,6 +733,10 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev) } =20 vfio_msi_disable_common(vdev); + vfio_intx_enable(vdev, &err); + if (err) { + error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); + } =20 memset(vdev->msix->pending, 0, BITS_TO_LONGS(vdev->msix->entries) * sizeof(unsigned long)); @@ -747,8 +746,14 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev) =20 static void vfio_msi_disable(VFIOPCIDevice *vdev) { + Error *err =3D NULL; + vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSI_IRQ_INDEX); vfio_msi_disable_common(vdev); + vfio_intx_enable(vdev, &err); + if (err) { + error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); + } =20 trace_vfio_msi_disable(vdev->vbasedev.name); } --=20 1.8.3.1 From nobody Tue May 7 14:26:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631168024937676.5257080258388; Wed, 8 Sep 2021 23:13:44 -0700 (PDT) Received: from localhost ([::1]:35608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mODJf-0007pU-OI for importer@patchew.org; Thu, 09 Sep 2021 02:13:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCk-0004DT-BQ for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:34 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:2858) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCe-000658-QQ for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:34 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4H4pQJ1TyQz1DGs8; Thu, 9 Sep 2021 14:05:28 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:20 +0800 Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:18 +0800 From: "Longpeng(Mike)" To: , , Subject: [PATCH v2 3/9] vfio: simplify the failure path in vfio_msi_enable Date: Thu, 9 Sep 2021 14:06:07 +0800 Message-ID: <20210909060613.2815-4-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20210909060613.2815-1-longpeng2@huawei.com> References: <20210909060613.2815-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected 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=45.249.212.255; envelope-from=longpeng2@huawei.com; helo=szxga08-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chenjiashang@huawei.com, mst@redhat.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, "Longpeng\(Mike\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631168026330100001 Content-Type: text/plain; charset="utf-8" Use vfio_msi_disable_common to simplify the error handling in vfio_msi_enable. Signed-off-by: Longpeng(Mike) --- hw/vfio/pci.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 1e6797f..8236cd7 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -655,24 +655,12 @@ retry: "MSI vectors, retry with %d", vdev->nr_vectors, r= et); } =20 - for (i =3D 0; i < vdev->nr_vectors; i++) { - VFIOMSIVector *vector =3D &vdev->msi_vectors[i]; - if (vector->virq >=3D 0) { - vfio_remove_kvm_msi_virq(vector); - } - qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), - NULL, NULL, NULL); - event_notifier_cleanup(&vector->interrupt); - } - - g_free(vdev->msi_vectors); - vdev->msi_vectors =3D NULL; + vfio_msi_disable_common(vdev); =20 if (ret > 0) { vdev->nr_vectors =3D ret; goto retry; } - vdev->nr_vectors =3D 0; =20 /* * Failing to setup MSI doesn't really fall within any specificati= on. @@ -680,7 +668,6 @@ retry: * out to fall back to INTx for this device. */ error_report("vfio: Error: Failed to enable MSI"); - vdev->interrupt =3D VFIO_INT_NONE; =20 return; } --=20 1.8.3.1 From nobody Tue May 7 14:26:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16311679314201010.5064687503345; Wed, 8 Sep 2021 23:12:11 -0700 (PDT) Received: from localhost ([::1]:60568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mODIA-0005bJ-Ds for importer@patchew.org; Thu, 09 Sep 2021 02:12:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCj-0004Ax-53 for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:33 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2230) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCe-000652-Qm for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:32 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4H4pQk1KMSz8t0m; Thu, 9 Sep 2021 14:05:50 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:20 +0800 Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:19 +0800 From: "Longpeng(Mike)" To: , , Subject: [PATCH v2 4/9] msix: simplify the conditional in msix_set/unset_vector_notifiers Date: Thu, 9 Sep 2021 14:06:08 +0800 Message-ID: <20210909060613.2815-5-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20210909060613.2815-1-longpeng2@huawei.com> References: <20210909060613.2815-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected 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=45.249.212.189; envelope-from=longpeng2@huawei.com; helo=szxga03-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chenjiashang@huawei.com, mst@redhat.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, "Longpeng\(Mike\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631167932948100005 Content-Type: text/plain; charset="utf-8" 'msix_function_masked' is synchronized with the device's config, we can use it to replace the complex conditional statementis in msix_set/unset_vector_notifiers. Signed-off-by: Longpeng(Mike) --- hw/pci/msix.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/pci/msix.c b/hw/pci/msix.c index ae9331c..6768228 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -592,8 +592,7 @@ int msix_set_vector_notifiers(PCIDevice *dev, dev->msix_vector_release_notifier =3D release_notifier; dev->msix_vector_poll_notifier =3D poll_notifier; =20 - if ((dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & - (MSIX_ENABLE_MASK | MSIX_MASKALL_MASK)) =3D=3D MSIX_ENABLE_MASK) { + if (!dev->msix_function_masked) { for (vector =3D 0; vector < dev->msix_entries_nr; vector++) { ret =3D msix_set_notifier_for_vector(dev, vector); if (ret < 0) { @@ -622,8 +621,7 @@ void msix_unset_vector_notifiers(PCIDevice *dev) assert(dev->msix_vector_use_notifier && dev->msix_vector_release_notifier); =20 - if ((dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & - (MSIX_ENABLE_MASK | MSIX_MASKALL_MASK)) =3D=3D MSIX_ENABLE_MASK) { + if (!dev->msix_function_masked) { for (vector =3D 0; vector < dev->msix_entries_nr; vector++) { msix_unset_notifier_for_vector(dev, vector); } --=20 1.8.3.1 From nobody Tue May 7 14:26:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631167713397190.54166999262418; Wed, 8 Sep 2021 23:08:33 -0700 (PDT) Received: from localhost ([::1]:51590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mODEe-0007pQ-EZ for importer@patchew.org; Thu, 09 Sep 2021 02:08:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCh-00046c-2I for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:31 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCe-000653-Md for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:30 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H4pLg3zdbzbmNx; Thu, 9 Sep 2021 14:02:19 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:20 +0800 Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:19 +0800 From: "Longpeng(Mike)" To: , , Subject: [PATCH v2 5/9] msix: reset poll_notifier to NULL if fail to set notifiers Date: Thu, 9 Sep 2021 14:06:09 +0800 Message-ID: <20210909060613.2815-6-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20210909060613.2815-1-longpeng2@huawei.com> References: <20210909060613.2815-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected 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=45.249.212.187; envelope-from=longpeng2@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chenjiashang@huawei.com, mst@redhat.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, "Longpeng\(Mike\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631167714859100001 Content-Type: text/plain; charset="utf-8" 'msix_vector_poll_notifier' should be reset to NULL in the error path in msix_set_vector_notifiers(). Signed-off-by: Longpeng(Mike) --- hw/pci/msix.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/pci/msix.c b/hw/pci/msix.c index 6768228..8057709 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -611,6 +611,7 @@ undo: } dev->msix_vector_use_notifier =3D NULL; dev->msix_vector_release_notifier =3D NULL; + dev->msix_vector_poll_notifier =3D NULL; return ret; } =20 --=20 1.8.3.1 From nobody Tue May 7 14:26:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631167818829716.5313463806715; Wed, 8 Sep 2021 23:10:18 -0700 (PDT) Received: from localhost ([::1]:57480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mODGL-0003QQ-SC for importer@patchew.org; Thu, 09 Sep 2021 02:10:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCh-00048F-P1 for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:31 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2918) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCe-000651-Mu for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:31 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H4pLg4l1nzbmNh; Thu, 9 Sep 2021 14:02:19 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:21 +0800 Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:20 +0800 From: "Longpeng(Mike)" To: , , Subject: [PATCH v2 6/9] kvm: irqchip: extract kvm_irqchip_add_deferred_msi_route Date: Thu, 9 Sep 2021 14:06:10 +0800 Message-ID: <20210909060613.2815-7-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20210909060613.2815-1-longpeng2@huawei.com> References: <20210909060613.2815-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected 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=45.249.212.187; envelope-from=longpeng2@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chenjiashang@huawei.com, mst@redhat.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, "Longpeng\(Mike\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631167819888100001 Content-Type: text/plain; charset="utf-8" Extract a common helper that add MSI route for specific vector but does not commit immediately. Signed-off-by: Longpeng(Mike) --- accel/kvm/kvm-all.c | 15 +++++++++++++-- include/sysemu/kvm.h | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 0125c17..13cdd01 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1950,7 +1950,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg) return kvm_set_irq(s, route->kroute.gsi, 1); } =20 -int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev) +int kvm_irqchip_add_deferred_msi_route(KVMState *s, int vector, PCIDevice = *dev) { struct kvm_irq_routing_entry kroute =3D {}; int virq; @@ -1993,7 +1993,18 @@ int kvm_irqchip_add_msi_route(KVMState *s, int vecto= r, PCIDevice *dev) =20 kvm_add_routing_entry(s, &kroute); kvm_arch_add_msi_route_post(&kroute, vector, dev); - kvm_irqchip_commit_routes(s); + + return virq; +} + +int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev) +{ + int virq; + + virq =3D kvm_irqchip_add_deferred_msi_route(s, vector, dev); + if (virq >=3D 0) { + kvm_irqchip_commit_routes(s); + } =20 return virq; } diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index a1ab1ee..8de0d9a 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -476,6 +476,12 @@ void kvm_init_cpu_signals(CPUState *cpu); * @return: virq (>=3D0) when success, errno (<0) when failed. */ int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev); +/** + * Add MSI route for specific vector but does not commit to KVM + * immediately + */ +int kvm_irqchip_add_deferred_msi_route(KVMState *s, int vector, + PCIDevice *dev); int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg, PCIDevice *dev); void kvm_irqchip_commit_routes(KVMState *s); --=20 1.8.3.1 From nobody Tue May 7 14:26:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631168248783417.09428076685833; Wed, 8 Sep 2021 23:17:28 -0700 (PDT) Received: from localhost ([::1]:43038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mODNH-0004Sn-Qw for importer@patchew.org; Thu, 09 Sep 2021 02:17:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCl-0004F6-5z for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:35 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:2859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCe-000657-OT for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:34 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4H4pQJ4qQKz1DGsD; Thu, 9 Sep 2021 14:05:28 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:21 +0800 Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:20 +0800 From: "Longpeng(Mike)" To: , , Subject: [PATCH v2 7/9] vfio: add infrastructure to commit the deferred kvm routing Date: Thu, 9 Sep 2021 14:06:11 +0800 Message-ID: <20210909060613.2815-8-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20210909060613.2815-1-longpeng2@huawei.com> References: <20210909060613.2815-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected 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=45.249.212.255; envelope-from=longpeng2@huawei.com; helo=szxga08-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chenjiashang@huawei.com, mst@redhat.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, "Longpeng\(Mike\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631168249813100001 Content-Type: text/plain; charset="utf-8" 'defer_kvm_irq_routing' indicates whether we should defer to commit the kvm routing. Signed-off-by: Longpeng(Mike) --- hw/vfio/pci.c | 42 +++++++++++++++++++++++++++++++++++++++++- hw/vfio/pci.h | 1 + 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 8236cd7..dda60a5 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -422,12 +422,24 @@ static void vfio_add_kvm_msi_virq(VFIOPCIDevice *vdev= , VFIOMSIVector *vector, return; } =20 - virq =3D kvm_irqchip_add_msi_route(kvm_state, vector_n, &vdev->pdev); + virq =3D kvm_irqchip_add_deferred_msi_route(kvm_state, vector_n, &vdev= ->pdev); if (virq < 0) { event_notifier_cleanup(&vector->kvm_interrupt); return; } =20 + if (vdev->defer_kvm_irq_routing) { + /* + * Hold the allocated virq in vector->virq temporarily, will + * reset it to -1 when we fail to add the corresponding irqfd + * in vfio_commit_kvm_msi_virq(). + */ + vector->virq =3D virq; + return; + } + + kvm_irqchip_commit_routes(); + if (kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, &vector->kvm_interru= pt, NULL, virq) < 0) { kvm_irqchip_release_virq(kvm_state, virq); @@ -566,6 +578,34 @@ static void vfio_msix_vector_release(PCIDevice *pdev, = unsigned int nr) } } =20 +static void vfio_commit_kvm_msi_virq(VFIOPCIDevice *vdev) +{ + int i; + VFIOMSIVector *vector; + + if (!vdev->defer_kvm_irq_routing || !vdev->nr_vectors) { + return; + } + + kvm_irqchip_commit_routes(kvm_state); + + for (i =3D 0; i < vdev->nr_vectors; i++) { + vector =3D &vdev->msi_vectors[i]; + + if (!vector->use || vector->virq < 0) { + continue; + } + + if (kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, + &vector->kvm_interrupt, + NULL, vector->virq) < 0) { + kvm_irqchip_release_virq(kvm_state, vector->virq); + event_notifier_cleanup(&vector->kvm_interrupt); + vector->virq =3D -1; + } + } +} + static void vfio_msix_enable(VFIOPCIDevice *vdev) { PCIDevice *pdev =3D &vdev->pdev; diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 6477751..d3c5177 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -171,6 +171,7 @@ struct VFIOPCIDevice { bool no_kvm_ioeventfd; bool no_vfio_ioeventfd; bool enable_ramfb; + bool defer_kvm_irq_routing; VFIODisplay *dpy; Notifier irqchip_change_notifier; }; --=20 1.8.3.1 From nobody Tue May 7 14:26:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631167683749169.86039546190898; Wed, 8 Sep 2021 23:08:03 -0700 (PDT) Received: from localhost ([::1]:50116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mODEA-0006sD-9w for importer@patchew.org; Thu, 09 Sep 2021 02:08:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCi-0004AV-UX for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:32 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3132) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCe-00065B-Pj for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:32 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H4pLJ2HbPz8yPV; Thu, 9 Sep 2021 14:02:00 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:21 +0800 Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:21 +0800 From: "Longpeng(Mike)" To: , , Subject: [PATCH v2 8/9] Revert "vfio: Avoid disabling and enabling vectors repeatedly in VFIO migration" Date: Thu, 9 Sep 2021 14:06:12 +0800 Message-ID: <20210909060613.2815-9-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20210909060613.2815-1-longpeng2@huawei.com> References: <20210909060613.2815-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected 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=45.249.212.188; envelope-from=longpeng2@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chenjiashang@huawei.com, mst@redhat.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, "Longpeng\(Mike\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631167684289100001 Content-Type: text/plain; charset="utf-8" Commit ecebe53fe993 ("vfio: Avoid disabling and enabling vectors repeatedly in VFIO migration") avoid inefficiently disabling and enabling vectors repeatedly and let the unmasked vectors to be enabled one by one. But we want to batch multiple routes and defer the commit, and only commit once out side the loop of setting vector notifiers, so we cannot to enable the vectors one by one in the loop now. Revert that commit and we will take another way in the next patch, it can not only avoid disabling/enabling vectors repeatedly, but also satisfy our requirement of defer to commit. Signed-off-by: Longpeng(Mike) --- hw/vfio/pci.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index dda60a5..4aedb5a 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -608,9 +608,6 @@ static void vfio_commit_kvm_msi_virq(VFIOPCIDevice *vde= v) =20 static void vfio_msix_enable(VFIOPCIDevice *vdev) { - PCIDevice *pdev =3D &vdev->pdev; - unsigned int nr, max_vec =3D 0; - vfio_disable_interrupts(vdev); =20 vdev->msi_vectors =3D g_new0(VFIOMSIVector, vdev->msix->entries); @@ -629,22 +626,11 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev) * triggering to userspace, then immediately release the vector, leavi= ng * the physical device with no vectors enabled, but MSI-X enabled, just * like the guest view. - * If there are already unmasked vectors (in migration resume phase and - * some guest startups) which will be enabled soon, we can allocate all - * of them here to avoid inefficiently disabling and enabling vectors - * repeatedly later. */ - if (!pdev->msix_function_masked) { - for (nr =3D 0; nr < msix_nr_vectors_allocated(pdev); nr++) { - if (!msix_is_masked(pdev, nr)) { - max_vec =3D nr; - } - } - } - vfio_msix_vector_do_use(pdev, max_vec, NULL, NULL); - vfio_msix_vector_release(pdev, max_vec); + vfio_msix_vector_do_use(&vdev->pdev, 0, NULL, NULL); + vfio_msix_vector_release(&vdev->pdev, 0); =20 - if (msix_set_vector_notifiers(pdev, vfio_msix_vector_use, + 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 1.8.3.1 From nobody Tue May 7 14:26:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631168099324996.6070787898723; Wed, 8 Sep 2021 23:14:59 -0700 (PDT) Received: from localhost ([::1]:38680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mODKs-0001St-9v for importer@patchew.org; Thu, 09 Sep 2021 02:14:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCk-0004Dn-Gf for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:34 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2792) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mODCe-00065E-QN for qemu-devel@nongnu.org; Thu, 09 Sep 2021 02:06:34 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H4pLh3tLlzQvHV; Thu, 9 Sep 2021 14:02:20 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:22 +0800 Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 9 Sep 2021 14:06:21 +0800 From: "Longpeng(Mike)" To: , , Subject: [PATCH v2 9/9] vfio: defer to commit kvm irq routing when enable msi/msix Date: Thu, 9 Sep 2021 14:06:13 +0800 Message-ID: <20210909060613.2815-10-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20210909060613.2815-1-longpeng2@huawei.com> References: <20210909060613.2815-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected 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=45.249.212.188; envelope-from=longpeng2@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chenjiashang@huawei.com, mst@redhat.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, "Longpeng\(Mike\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631168101422100001 Content-Type: text/plain; charset="utf-8" In migration resume phase, all unmasked msix vectors need to be setup when load the VF state. However, the setup operation would take longer if the VM has more VFs and each VF has more unmasked vectors. The hot spot is kvm_irqchip_commit_routes, it'll scan and update all irqfds that already assigned each invocation, so more vectors means need more time to process them. vfio_pci_load_config vfio_msix_enable msix_set_vector_notifiers for (vector =3D 0; vector < dev->msix_entries_nr; vector++) { vfio_msix_vector_do_use vfio_add_kvm_msi_virq kvm_irqchip_commit_routes <-- expensive } We can reduce the cost by only commit once outside the loop. The routes is cached in kvm_state, we commit them first and then bind irqfd for each vector. The test VM has 128 vcpus and 8 VF (each one has 65 vectors), we measure the cost of the vfio_msix_enable for each VF, and we can see 90+% costs can be reduce. VF Count of irqfds[*] Original With this patch 1st 65 8 2 2nd 130 15 2 3rd 195 22 2 4th 260 24 3 5th 325 36 2 6th 390 44 3 7th 455 51 3 8th 520 58 4 Total 258ms 21ms [*] Count of irqfds How many irqfds that already assigned and need to process in this round. The optimition can be applied to msi type too. Signed-off-by: Longpeng(Mike) --- hw/vfio/pci.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 4aedb5a..cc85cc1 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -512,11 +512,13 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, u= nsigned int nr, * increase them as needed. */ if (vdev->nr_vectors < nr + 1) { - vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX); vdev->nr_vectors =3D nr + 1; - ret =3D vfio_enable_vectors(vdev, true); - if (ret) { - error_report("vfio: failed to enable vectors, %d", ret); + if (!vdev->defer_kvm_irq_routing) { + vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX= ); + ret =3D vfio_enable_vectors(vdev, true); + if (ret) { + error_report("vfio: failed to enable vectors, %d", ret); + } } } else { Error *err =3D NULL; @@ -608,6 +610,9 @@ static void vfio_commit_kvm_msi_virq(VFIOPCIDevice *vde= v) =20 static void vfio_msix_enable(VFIOPCIDevice *vdev) { + PCIDevice *pdev =3D &vdev->pdev; + int ret; + vfio_disable_interrupts(vdev); =20 vdev->msi_vectors =3D g_new0(VFIOMSIVector, vdev->msix->entries); @@ -630,11 +635,22 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev) vfio_msix_vector_do_use(&vdev->pdev, 0, NULL, NULL); vfio_msix_vector_release(&vdev->pdev, 0); =20 - if (msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use, - vfio_msix_vector_release, NULL)) { + vdev->defer_kvm_irq_routing =3D true; + + ret =3D msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use, + vfio_msix_vector_release, NULL); + if (ret < 0) { error_report("vfio: msix_set_vector_notifiers failed"); + } else if (!pdev->msix_function_masked) { + vfio_commit_kvm_msi_virq(vdev); + vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX); + ret =3D vfio_enable_vectors(vdev, true); + if (ret) { + error_report("vfio: failed to enable vectors, %d", ret); + } } =20 + vdev->defer_kvm_irq_routing =3D false; trace_vfio_msix_enable(vdev->vbasedev.name); } =20 @@ -643,6 +659,7 @@ static void vfio_msi_enable(VFIOPCIDevice *vdev) int ret, i; =20 vfio_disable_interrupts(vdev); + vdev->defer_kvm_irq_routing =3D true; =20 vdev->nr_vectors =3D msi_nr_vectors_allocated(&vdev->pdev); retry: @@ -669,6 +686,8 @@ retry: vfio_add_kvm_msi_virq(vdev, vector, i, false); } =20 + vfio_commit_kvm_msi_virq(vdev); + /* Set interrupt type prior to possible interrupts */ vdev->interrupt =3D VFIO_INT_MSI; =20 @@ -695,9 +714,11 @@ retry: */ error_report("vfio: Error: Failed to enable MSI"); =20 + vdev->defer_kvm_irq_routing =3D false; return; } =20 + vdev->defer_kvm_irq_routing =3D false; trace_vfio_msi_enable(vdev->vbasedev.name, vdev->nr_vectors); } =20 --=20 1.8.3.1