From nobody Sat May 18 23:55:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1690466774; cv=none; d=zohomail.com; s=zohoarc; b=DdhCbii/WtGtVZprVXmb5V9MHKXlMqNXnPX8ejVyQwEJRuk7vPzsGuo9NnC3LnOibiVJUiyrbyhcbvHgnxcGhGKacay0UVLabTKkPYfPEoyGiMX0V5dJdVRaSFir6jCaYi4nHjqQbH9Nd1Is+Sg6PaXGdFqtyPCmcT1PpkgqsLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690466774; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dnUWUodB59z3MTAlCxhee+aJh++1Y/H49KHoMrGh3VU=; b=gqOq+hq6vUveNJAbSx+M2rgH9hcAo72AS9FcWgnHrL+mdK3Y1TPsXOGbi75inn0MsyWpdEs+qXQ1sjia6pPCrKswsQGMrr6M3jMYVkchl1Rj08j9zb6/q3o/nUGuTeP9HgrVSbKjaZVqzhe6EHjXQxGHuKRWOexv12mFydtyLMc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690466774087688.0273994613061; Thu, 27 Jul 2023 07:06:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP1H5-00061j-Um; Thu, 27 Jul 2023 09:43:27 -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 1qOvVv-0005f9-7C for qemu-devel@nongnu.org; Thu, 27 Jul 2023 03:34:23 -0400 Received: from [192.55.52.136] (helo=mgamail.intel.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOvVt-0004N7-GO for qemu-devel@nongnu.org; Thu, 27 Jul 2023 03:34:22 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2023 00:24:17 -0700 Received: from vmmteam.bj.intel.com ([10.240.192.110]) by orsmga008.jf.intel.com with ESMTP; 27 Jul 2023 00:24:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690443261; x=1721979261; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WABoFA/wWazeez7zhBvvVv7o7DbqHVzXK2WHrjvGk54=; b=mqeCJvk3fU0Rlz0yfHpMRYTsF8sDNpxB+dBu04r5c0GhenSYvYDjsXxw y4z2Kj9EizYWcF8VZ9bpMBfwL9QJd4mrukdJtBbcbn8XKn7MuEPiOE3hj CKP6Ug+dZVH6vTAMSddVBx/HlAn5kuIyHfZhq4ihqDADI872p9qzNVoXt Iqx1I8ph/gEQyTDnreCj/1afBL+vS6iCEejhHyvHbJb8DxkRxcaQtDo8t T2p99loWjbEycfKy33HUCpn3DJPTfJUpomJaa+tQn1mrHCCZ79myH6sRt fuqgJuesctc0XvKFM44A0pA/I10GAgXZ5yNqBgZtKTL1r9KFv4nN+9M8N g==; X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="347842868" X-IronPort-AV: E=Sophos;i="6.01,234,1684825200"; d="scan'208";a="347842868" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="756547369" X-IronPort-AV: E=Sophos;i="6.01,234,1684825200"; d="scan'208";a="756547369" From: Jing Liu To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, pbonzini@redhat.com, kevin.tian@intel.com, reinette.chatre@intel.com, jing2.liu@intel.com Subject: [PATCH RFC v1 1/3] vfio/pci: detect the support of dynamic MSI-X allocation Date: Thu, 27 Jul 2023 03:24:08 -0400 Message-Id: <20230727072410.135743-2-jing2.liu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230727072410.135743-1-jing2.liu@intel.com> References: <20230727072410.135743-1-jing2.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 192.55.52.136 (failed) 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=192.55.52.136; envelope-from=jing2.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 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_MED=-2.3, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 27 Jul 2023 09:43:26 -0400 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 @intel.com) X-ZM-MESSAGEID: 1690466848701100001 Content-Type: text/plain; charset="utf-8" From: Reinette Chatre Kernel provides the guidance of dynamic MSI-X allocation support of passthrough device, by clearing the VFIO_IRQ_INFO_NORESIZE flag to guide user space. Fetch and store the flags from host for later use to determine if specific flags are set. Signed-off-by: Reinette Chatre Signed-off-by: Jing Liu --- hw/vfio/pci.c | 12 ++++++++++++ hw/vfio/pci.h | 1 + hw/vfio/trace-events | 2 ++ 3 files changed, 15 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index a205c6b1130f..0c4ac0873d40 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1572,6 +1572,7 @@ static void vfio_msix_early_setup(VFIOPCIDevice *vdev= , Error **errp) =20 static int vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp) { + struct vfio_irq_info irq_info =3D { .argsz =3D sizeof(irq_info) }; int ret; Error *err =3D NULL; =20 @@ -1624,6 +1625,17 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int = pos, Error **errp) memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false); } =20 + irq_info.index =3D VFIO_PCI_MSIX_IRQ_INDEX; + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info); + if (ret) { + /* This can fail for an old kernel or legacy PCI dev */ + trace_vfio_msix_setup_get_irq_info_failure(strerror(errno)); + } else { + vdev->msix->irq_info_flags =3D irq_info.flags; + } + trace_vfio_msix_setup_irq_info_flags(vdev->vbasedev.name, + vdev->msix->irq_info_flags); + return 0; } =20 diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index a2771b9ff3cc..ad34ec56d0ae 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -113,6 +113,7 @@ typedef struct VFIOMSIXInfo { uint32_t table_offset; uint32_t pba_offset; unsigned long *pending; + uint32_t irq_info_flags; } VFIOMSIXInfo; =20 #define TYPE_VFIO_PCI "vfio-pci" diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index ee7509e68e4f..7d4a398f044d 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -28,6 +28,8 @@ vfio_pci_read_config(const char *name, int addr, int len,= int val) " (%s, @0x%x, vfio_pci_write_config(const char *name, int addr, int val, int len) " (%s,= @0x%x, 0x%x, len=3D0x%x)" vfio_msi_setup(const char *name, int pos) "%s PCI MSI CAP @0x%x" vfio_msix_early_setup(const char *name, int pos, int table_bar, int offset= , int entries) "%s PCI MSI-X CAP @0x%x, BAR %d, offset 0x%x, entries %d" +vfio_msix_setup_get_irq_info_failure(const char *errstr) "VFIO_DEVICE_GET_= IRQ_INFO failure: %s" +vfio_msix_setup_irq_info_flags(const char *name, uint32_t flags) " (%s) MS= I-X irq info flags 0x%x" vfio_check_pcie_flr(const char *name) "%s Supports FLR via PCIe cap" vfio_check_pm_reset(const char *name) "%s Supports PM reset" vfio_check_af_flr(const char *name) "%s Supports FLR via AF cap" --=20 2.27.0 From nobody Sat May 18 23:55:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1690466314; cv=none; d=zohomail.com; s=zohoarc; b=Z7g5vW4LgKXhlqQm32d6cOlQ8upYKQhiADAsnGkoAXk93azJVteAOxxcfDGiDUYwxdsGIMmu+9MCjF5cwA8NExhDE0RNqnLWaVGDtOxV2Z9qiDpMNA7Joys20ZTqCKNwNMQ6sgilY4nB5IJ2fFgzrogEtv0pmiGzYd/AktKKG10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690466314; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GDRb0DUq+IXFQse0KJ5M9OynIDme5X6CJG8YsmdFFJU=; b=Qq1KiuQdcLEK5EIPBTJx6tB0GEz33LNDlNRsMCoc7z3xjVJjR/IYTWOKGB56q5rcideH6UYY4+4ieq6wFGkAZnAJ8FpYctc08bdrUfFw6Kg0HY51cEPuL5YFdqFLLRSNakY7FhqRQcPuEkzbJBYwb68ZiMdnEwXOXcwppoYQ41I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690466314220742.6509325322289; Thu, 27 Jul 2023 06:58:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP1H6-00062E-EF; Thu, 27 Jul 2023 09:43: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 1qOvVt-0005ew-1y for qemu-devel@nongnu.org; Thu, 27 Jul 2023 03:34:21 -0400 Received: from [192.55.52.136] (helo=mgamail.intel.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOvVr-0004N7-CH for qemu-devel@nongnu.org; Thu, 27 Jul 2023 03:34:20 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2023 00:24:20 -0700 Received: from vmmteam.bj.intel.com ([10.240.192.110]) by orsmga008.jf.intel.com with ESMTP; 27 Jul 2023 00:24:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690443259; x=1721979259; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=loxFiijST0IQty0YeY0ldu2O+ixiW/kkhN5LYkEB+U0=; b=TKCDCWI7MMVs3rIuqS861z1NIQN6zxmd/1bKz1IFFegSSit63oLihP+H wX3utb+wFcjJ05hoXQu5O5BiRtvx9m/U9JHCMNNFDz1kSsB3SOlpH/Gwq LHQQfK87PNVSQX0nVm/bgGZG1LnEj5F3As1hYlYWoyX0KK3tUiH8ssYn+ Wi4yKpRmU61AiMbPqE44C6uxZ7Xv17/odl9F3u1S5LQ+EeleYYBHBfUAW gw91O/nnbxjSPMJ/ze9bRlpqOzb5xkA7c5Pxz18gFEmno5WakCoKaruVS zLH6U4HtSLRN4B8q0W4Wb+pnS+uJJDSvkbZJPtz8/WMb4h+G6MNgeEDV+ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="347842874" X-IronPort-AV: E=Sophos;i="6.01,234,1684825200"; d="scan'208";a="347842874" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="756547372" X-IronPort-AV: E=Sophos;i="6.01,234,1684825200"; d="scan'208";a="756547372" From: Jing Liu To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, pbonzini@redhat.com, kevin.tian@intel.com, reinette.chatre@intel.com, jing2.liu@intel.com Subject: [PATCH RFC v1 2/3] vfio/pci: enable vector on dynamic MSI-X allocation Date: Thu, 27 Jul 2023 03:24:09 -0400 Message-Id: <20230727072410.135743-3-jing2.liu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230727072410.135743-1-jing2.liu@intel.com> References: <20230727072410.135743-1-jing2.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 192.55.52.136 (failed) 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=192.55.52.136; envelope-from=jing2.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 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_MED=-2.3, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 27 Jul 2023 09:43:26 -0400 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 @intel.com) X-ZM-MESSAGEID: 1690466315980100003 Content-Type: text/plain; charset="utf-8" The vector_use callback is used to enable vector that is unmasked in guest. The kernel used to only support static MSI-X allocation. When allocating a new interrupt using "static MSI-X allocation" kernels, Qemu first disables all previously allocated vectors and then re-allocates all including the new one. The nr_vectors of VFIOPCIDevice indicates that all vectors from 0 to nr_vectors are allocated (and may be enabled), which is used to to loop all the possibly used vectors When, e.g., disabling MSI-X interrupts. Extend the vector_use function to support dynamic MSI-X allocation when host supports the capability. Qemu therefore can individually allocate and enable a new interrupt without affecting others or causing interrupts lost during runtime. Utilize nr_vectors to calculate the upper bound of enabled vectors in dynamic MSI-X allocation mode since looping all msix_entries_nr is not efficient and unnecessary. Signed-off-by: Jing Liu Tested-by: Reinette Chatre --- hw/vfio/pci.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 0c4ac0873d40..8c485636445c 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -512,12 +512,20 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, u= nsigned int nr, } =20 /* - * We don't want to have the host allocate all possible MSI vectors - * for a device if they're not in use, so we shutdown and incrementally - * increase them as needed. + * When dynamic allocation is not supported, we don't want to have the + * host allocate all possible MSI vectors for a device if they're not + * in use, so we shutdown and incrementally increase them as needed. + * And nr_vectors stands for the number of vectors being allocated. + * + * When dynamic allocation is supported, let the host only allocate + * and enable a vector when it is in use in guest. nr_vectors stands + * for the upper bound of vectors being enabled (but not all of the + * ranges is allocated or enabled). */ - if (vdev->nr_vectors < nr + 1) { + if ((vdev->msix->irq_info_flags & VFIO_IRQ_INFO_NORESIZE) && + (vdev->nr_vectors < nr + 1)) { vdev->nr_vectors =3D nr + 1; + if (!vdev->defer_kvm_irq_routing) { vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX= ); ret =3D vfio_enable_vectors(vdev, true); @@ -529,16 +537,22 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, u= nsigned int nr, Error *err =3D NULL; int32_t fd; =20 - if (vector->virq >=3D 0) { - fd =3D event_notifier_get_fd(&vector->kvm_interrupt); - } else { - fd =3D event_notifier_get_fd(&vector->interrupt); - } + if (!vdev->defer_kvm_irq_routing) { + if (vector->virq >=3D 0) { + fd =3D event_notifier_get_fd(&vector->kvm_interrupt); + } else { + fd =3D event_notifier_get_fd(&vector->interrupt); + } =20 - if (vfio_set_irq_signaling(&vdev->vbasedev, - VFIO_PCI_MSIX_IRQ_INDEX, nr, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err= )) { - error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); + if (vfio_set_irq_signaling(&vdev->vbasedev, + VFIO_PCI_MSIX_IRQ_INDEX, nr, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, &e= rr)) { + error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.nam= e); + } + } + /* Increase for dynamic allocation case. */ + if (vdev->nr_vectors < nr + 1) { + vdev->nr_vectors =3D nr + 1; } } =20 --=20 2.27.0 From nobody Sat May 18 23:55:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1690466179; cv=none; d=zohomail.com; s=zohoarc; b=mOKQt3MkoTAVt/FbtnY9q+Na4XZ3u4XhT8bzMqTqhigB0mvl12Y1l0Wpp004GT5TZcHQ9LNI9bsB4HB4jEyEm5oz2ch5hQ8HEHh/NEq5yZFJkTAXTbDlFZEsY7DOovTVE9ms3Cs58WcdTmQaONwYKmDzPK+lyVZT6bwxxGLZVc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690466179; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EmH1WCjz8n0p9jzhm4Xobxb1krJtfZ4tAX+ZLFdHBuQ=; b=ah2htVOAmey8mwelNFml+cLPLWgMC7xWISGLV6Gb5Ep5aghwvSvgJTKunL9hUGvqm5MacqyLWDqDr1PhTG3iUcUbZVuWzFfxwnOUunCrLDluWKYCJeuue5zBPynz2CSNyDXXpm0E6rMBaHp9qYADNHm6M61cGagsCnAgUesU3S8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690466179685359.8984354732785; Thu, 27 Jul 2023 06:56:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP1H6-00061h-6G; Thu, 27 Jul 2023 09:43: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 1qOvVv-0005fI-R0 for qemu-devel@nongnu.org; Thu, 27 Jul 2023 03:34:23 -0400 Received: from [192.55.52.136] (helo=mgamail.intel.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOvVu-0004Nk-78 for qemu-devel@nongnu.org; Thu, 27 Jul 2023 03:34:23 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2023 00:24:22 -0700 Received: from vmmteam.bj.intel.com ([10.240.192.110]) by orsmga008.jf.intel.com with ESMTP; 27 Jul 2023 00:24:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690443262; x=1721979262; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PDY6PXgBHsLC8cUf42XTMOY4sPIs93ocKgpDuj7Te6A=; b=E8V7UkQauWE6NxD3lEq7hN91mUUiqASGeR/S26ivYwvEFawx9NPxn/Op oIBHB5q6o7ScLT4HQWtaF7SaMC820GCPrlx5S7u/dXeOP9xoizNRRFwKu g2/VRiGisQfjZymScLh7/crZvjacZs5n+Vrw3a8f/PrSl5WKARZoOlOXJ k1Tg1r25OygI8Jc33BMWuiEEuSXR0Flq9d/9eOL10//JxOIod7KUOr8/W /nvxIBMXDzR80j+5gC4ew+dRaCO2nRWkDv6tUu6Mnp62Shx74mtfhobgt iNctoPtESSmhDt9FG3YKRP6WmVmuVa4j1cixkxvfUv5AHPQnShJyPH1KU Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="347842880" X-IronPort-AV: E=Sophos;i="6.01,234,1684825200"; d="scan'208";a="347842880" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="756547376" X-IronPort-AV: E=Sophos;i="6.01,234,1684825200"; d="scan'208";a="756547376" From: Jing Liu To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, pbonzini@redhat.com, kevin.tian@intel.com, reinette.chatre@intel.com, jing2.liu@intel.com Subject: [PATCH RFC v1 3/3] vfio/pci: dynamic MSI-X allocation in interrupt restoring Date: Thu, 27 Jul 2023 03:24:10 -0400 Message-Id: <20230727072410.135743-4-jing2.liu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230727072410.135743-1-jing2.liu@intel.com> References: <20230727072410.135743-1-jing2.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 192.55.52.136 (failed) 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=192.55.52.136; envelope-from=jing2.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 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_MED=-2.3, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 27 Jul 2023 09:43:26 -0400 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 @intel.com) X-ZM-MESSAGEID: 1690466180956100003 Content-Type: text/plain; charset="utf-8" During migration restoring, vfio_enable_vectors() is called to restore enabling MSI-X interrupts for assigned devices. It sets the range from 0 to nr_vectors to kernel to enable MSI-X and the vectors unmasked in guest. During the MSI-X enabling, all the vectors within the range are allocated according to the ioctl(). When dynamic MSI-X allocation is supported, we only want the guest unmasked vectors being allocated and enabled. Therefore, Qemu can first set vector 0 to enable MSI-X and after that, all the vectors can be allocated in need. Signed-off-by: Jing Liu --- hw/vfio/pci.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 8c485636445c..43ffacd5b36a 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -375,6 +375,38 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bo= ol msix) int ret =3D 0, i, argsz; int32_t *fds; =20 + /* + * If dynamic MSI-X allocation is supported, the vectors to be allocat= ed + * and enabled can be scattered. Before kernel enabling MSI-X, setting + * nr_vectors causes all these vectors being allocated on host. + * + * To keep allocation as needed, first setup vector 0 with an invalid + * fd to make MSI-X enabled, then enable vectors by setting all so that + * kernel allocates and enables interrupts only when enabled in guest. + */ + if (msix && !(vdev->msix->irq_info_flags & VFIO_IRQ_INFO_NORESIZE)) { + argsz =3D sizeof(*irq_set) + sizeof(*fds); + + irq_set =3D g_malloc0(argsz); + irq_set->argsz =3D argsz; + irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | + VFIO_IRQ_SET_ACTION_TRIGGER; + irq_set->index =3D msix ? VFIO_PCI_MSIX_IRQ_INDEX : + VFIO_PCI_MSI_IRQ_INDEX; + irq_set->start =3D 0; + irq_set->count =3D 1; + fds =3D (int32_t *)&irq_set->data; + fds[0] =3D -1; + + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); + + g_free(irq_set); + + if (ret) { + return ret; + } + } + argsz =3D sizeof(*irq_set) + (vdev->nr_vectors * sizeof(*fds)); =20 irq_set =3D g_malloc0(argsz); --=20 2.27.0