qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 01/15] util: vfio-helpers: Fix qemu_vfio_close()


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v4 01/15] util: vfio-helpers: Fix qemu_vfio_close()
Date: Fri, 17 Apr 2020 12:22:11 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 3/5/20 3:29 PM, David Hildenbrand wrote:
qemu_vfio_undo_mapping() will decrement the number of mappings and
reshuffle the array elements to fit into the reduced size.

Iterating over all elements like this does not work as expected, let's make
sure to remove all mappings properly.

Reviewed-by: Peter Xu <address@hidden>
Cc: Richard Henderson <address@hidden>
Cc: Paolo Bonzini <address@hidden>
Cc: Eduardo Habkost <address@hidden>
Cc: Marcel Apfelbaum <address@hidden>
Cc: Alex Williamson <address@hidden>
Cc: Stefan Hajnoczi <address@hidden>
Signed-off-by: David Hildenbrand <address@hidden>
---
  util/vfio-helpers.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index 9ec01bfe26..f31aa77ffe 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -695,13 +695,11 @@ static void qemu_vfio_reset(QEMUVFIOState *s)
  /* Close and free the VFIO resources. */
  void qemu_vfio_close(QEMUVFIOState *s)
  {
-    int i;
-
      if (!s) {
          return;
      }
-    for (i = 0; i < s->nr_mappings; ++i) {
-        qemu_vfio_undo_mapping(s, &s->mappings[i], NULL);
+    while (s->nr_mappings) {
+        qemu_vfio_undo_mapping(s, &s->mappings[s->nr_mappings - 1], NULL);
      }
      ram_block_notifier_remove(&s->ram_notifier);
      qemu_vfio_reset(s);


Reviewed-by: Philippe Mathieu-Daudé <address@hidden>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]