All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/2] VFIO updates 2022-09-27
@ 2022-09-27 22:28 Alex Williamson
  2022-09-27 22:29 ` [PULL 1/2] vfio/migration: Fix incorrect initialization value for parameters in VFIOMigration Alex Williamson
  2022-09-27 22:29 ` [PULL 2/2] vfio/common: Fix vfio_iommu_type1_info use after free Alex Williamson
  0 siblings, 2 replies; 3+ messages in thread
From: Alex Williamson @ 2022-09-27 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.williamson

The following changes since commit dbc4f48b5ab3e6d85f78aa4df6bd6ad561c3d152:

  Merge tag 'net-pull-request' of https://github.com/jasowang/qemu into staging (2022-09-27 11:08:36 -0400)

are available in the Git repository at:

  https://gitlab.com/alex.williamson/qemu.git tags/vfio-updates-20220927.1

for you to fetch changes up to 85b6d2b5fc25c9c0d10d493b3728183ab8f8e68a:

  vfio/common: Fix vfio_iommu_type1_info use after free (2022-09-27 14:26:42 -0600)

----------------------------------------------------------------
VFIO updates 2022-09-27

 * Fix initial values for migration state (Kunkun Jiang)

 * Fix a use-after-free error path (Alex Williamson)

----------------------------------------------------------------
Alex Williamson (1):
      vfio/common: Fix vfio_iommu_type1_info use after free

Kunkun Jiang (1):
      vfio/migration: Fix incorrect initialization value for parameters in VFIOMigration

 hw/vfio/common.c    | 36 +++++++++++++++++++-----------------
 hw/vfio/migration.c |  2 ++
 2 files changed, 21 insertions(+), 17 deletions(-)



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PULL 1/2] vfio/migration: Fix incorrect initialization value for parameters in VFIOMigration
  2022-09-27 22:28 [PULL 0/2] VFIO updates 2022-09-27 Alex Williamson
@ 2022-09-27 22:29 ` Alex Williamson
  2022-09-27 22:29 ` [PULL 2/2] vfio/common: Fix vfio_iommu_type1_info use after free Alex Williamson
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2022-09-27 22:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.williamson

From: Kunkun Jiang <jiangkunkun@huawei.com>

The structure VFIOMigration of a VFIODevice is allocated and initialized
in vfio_migration_init(). "device_state" and "vm_running" are initialized
to 0, indicating that VFIO device is_STOP and VM is not-running. The
initialization value is incorrect. According to the agreement, default
state of VFIO device is _RUNNING. And if a VFIO device is hot-plugged
while the VM is running, "vm_running" should be 1. This patch fixes it.

Fixes: 02a7e71b1e5b ("vfio: Add VM state change handler to know state of VM")
Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com>
Link: https://lore.kernel.org/r/20220711014651.1327-1-jiangkunkun@huawei.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 hw/vfio/migration.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index a6ad1f894561..3de4252111ee 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -806,6 +806,8 @@ static int vfio_migration_init(VFIODevice *vbasedev,
     }
 
     vbasedev->migration = g_new0(VFIOMigration, 1);
+    vbasedev->migration->device_state = VFIO_DEVICE_STATE_RUNNING;
+    vbasedev->migration->vm_running = runstate_is_running();
 
     ret = vfio_region_setup(obj, vbasedev, &vbasedev->migration->region,
                             info->index, "migration");




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PULL 2/2] vfio/common: Fix vfio_iommu_type1_info use after free
  2022-09-27 22:28 [PULL 0/2] VFIO updates 2022-09-27 Alex Williamson
  2022-09-27 22:29 ` [PULL 1/2] vfio/migration: Fix incorrect initialization value for parameters in VFIOMigration Alex Williamson
@ 2022-09-27 22:29 ` Alex Williamson
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2022-09-27 22:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.williamson

On error, vfio_get_iommu_info() frees and clears *info, but
vfio_connect_container() continues to use the pointer regardless
of the return value.  Restructure the code such that a failure
of this function triggers an error and clean up the remainder of
the function, including updating an outdated comment that had
drifted from its relevant line of code and using host page size
for a default for better compatibility on non-4KB systems.

Reported-by: Nicolin Chen <nicolinc@nvidia.com>
Link: https://lore.kernel.org/all/20220910004245.2878-1-nicolinc@nvidia.com/
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Link: https://lore.kernel.org/r/166326219630.3388898.12882473157184946072.stgit@omen
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 hw/vfio/common.c |   36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index ace9562a9ba1..6b5d8c0bf694 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -2111,29 +2111,31 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
     {
         struct vfio_iommu_type1_info *info;
 
-        /*
-         * FIXME: This assumes that a Type1 IOMMU can map any 64-bit
-         * IOVA whatsoever.  That's not actually true, but the current
-         * kernel interface doesn't tell us what it can map, and the
-         * existing Type1 IOMMUs generally support any IOVA we're
-         * going to actually try in practice.
-         */
         ret = vfio_get_iommu_info(container, &info);
+        if (ret) {
+            error_setg_errno(errp, -ret, "Failed to get VFIO IOMMU info");
+            goto enable_discards_exit;
+        }
 
-        if (ret || !(info->flags & VFIO_IOMMU_INFO_PGSIZES)) {
-            /* Assume 4k IOVA page size */
-            info->iova_pgsizes = 4096;
+        if (info->flags & VFIO_IOMMU_INFO_PGSIZES) {
+            container->pgsizes = info->iova_pgsizes;
+        } else {
+            container->pgsizes = qemu_real_host_page_size();
         }
-        vfio_host_win_add(container, 0, (hwaddr)-1, info->iova_pgsizes);
-        container->pgsizes = info->iova_pgsizes;
 
-        /* The default in the kernel ("dma_entry_limit") is 65535. */
-        container->dma_max_mappings = 65535;
-        if (!ret) {
-            vfio_get_info_dma_avail(info, &container->dma_max_mappings);
-            vfio_get_iommu_info_migration(container, info);
+        if (!vfio_get_info_dma_avail(info, &container->dma_max_mappings)) {
+            container->dma_max_mappings = 65535;
         }
+        vfio_get_iommu_info_migration(container, info);
         g_free(info);
+
+        /*
+         * FIXME: We should parse VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGE
+         * information to get the actual window extent rather than assume
+         * a 64-bit IOVA address space.
+         */
+        vfio_host_win_add(container, 0, (hwaddr)-1, container->pgsizes);
+
         break;
     }
     case VFIO_SPAPR_TCE_v2_IOMMU:




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-27 22:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27 22:28 [PULL 0/2] VFIO updates 2022-09-27 Alex Williamson
2022-09-27 22:29 ` [PULL 1/2] vfio/migration: Fix incorrect initialization value for parameters in VFIOMigration Alex Williamson
2022-09-27 22:29 ` [PULL 2/2] vfio/common: Fix vfio_iommu_type1_info use after free Alex Williamson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.