qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/2] ppc-for-2.9 queue 20170329
@ 2017-03-29  3:34 David Gibson
  2017-03-29  3:34 ` [Qemu-devel] [PULL 1/2] spapr: fix buffer-overflow David Gibson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Gibson @ 2017-03-29  3:34 UTC (permalink / raw)
  To: peter.maydell
  Cc: qemu-devel, qemu-ppc, thuth, lvivier, mdroth, aik, agraf,
	David Gibson

The following changes since commit df9046363220e57d45818312759b954c033c58ab:

  Update version for v2.9.0-rc2 release (2017-03-28 19:11:16 +0100)

are available in the git repository at:

  git://github.com/dgibson/qemu.git tags/ppc-for-2.9-20170329

for you to fetch changes up to fe6824d12642b005c69123ecf8631f9b13553f8b:

  spapr: fix memory hot-unplugging (2017-03-29 11:35:16 +1100)

----------------------------------------------------------------
ppc patch queue for 2017-03-29

Two more bugfixes of sufficient severity to warrant going into 2.9.

----------------------------------------------------------------
Laurent Vivier (1):
      spapr: fix memory hot-unplugging

Marc-André Lureau (1):
      spapr: fix buffer-overflow

 hw/ppc/spapr.c             |  4 ++--
 hw/ppc/spapr_drc.c         | 20 +++++++++++++++++---
 include/hw/ppc/spapr_drc.h |  1 +
 3 files changed, 20 insertions(+), 5 deletions(-)

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

* [Qemu-devel] [PULL 1/2] spapr: fix buffer-overflow
  2017-03-29  3:34 [Qemu-devel] [PULL 0/2] ppc-for-2.9 queue 20170329 David Gibson
@ 2017-03-29  3:34 ` David Gibson
  2017-03-29  3:34 ` [Qemu-devel] [PULL 2/2] spapr: fix memory hot-unplugging David Gibson
  2017-03-30 14:27 ` [Qemu-devel] [PULL 0/2] ppc-for-2.9 queue 20170329 Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2017-03-29  3:34 UTC (permalink / raw)
  To: peter.maydell
  Cc: qemu-devel, qemu-ppc, thuth, lvivier, mdroth, aik, agraf,
	Marc-André Lureau, David Gibson

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Running postcopy-test with ASAN produces the following error:

QTEST_QEMU_BINARY=ppc64-softmmu/qemu-system-ppc64  tests/postcopy-test
...
=================================================================
==23641==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f1556600000 at pc 0x55b8e9d28208 bp 0x7f1555f4d3c0 sp 0x7f1555f4d3b0
READ of size 8 at 0x7f1556600000 thread T6
    #0 0x55b8e9d28207 in htab_save_first_pass /home/elmarco/src/qq/hw/ppc/spapr.c:1528
    #1 0x55b8e9d2939c in htab_save_iterate /home/elmarco/src/qq/hw/ppc/spapr.c:1665
    #2 0x55b8e9beae3a in qemu_savevm_state_iterate /home/elmarco/src/qq/migration/savevm.c:1044
    #3 0x55b8ea677733 in migration_thread /home/elmarco/src/qq/migration/migration.c:1976
    #4 0x7f15845f46c9 in start_thread (/lib64/libpthread.so.0+0x76c9)
    #5 0x7f157d9d0f7e in clone (/lib64/libc.so.6+0x107f7e)

0x7f1556600000 is located 0 bytes to the right of 2097152-byte region [0x7f1556400000,0x7f1556600000)
allocated by thread T0 here:
    #0 0x7f159bb76980 in posix_memalign (/lib64/libasan.so.3+0xc7980)
    #1 0x55b8eab185b2 in qemu_try_memalign /home/elmarco/src/qq/util/oslib-posix.c:106
    #2 0x55b8eab186c8 in qemu_memalign /home/elmarco/src/qq/util/oslib-posix.c:122
    #3 0x55b8e9d268a8 in spapr_reallocate_hpt /home/elmarco/src/qq/hw/ppc/spapr.c:1214
    #4 0x55b8e9d26e04 in ppc_spapr_reset /home/elmarco/src/qq/hw/ppc/spapr.c:1261
    #5 0x55b8ea12e913 in qemu_system_reset /home/elmarco/src/qq/vl.c:1697
    #6 0x55b8ea13fa40 in main /home/elmarco/src/qq/vl.c:4679
    #7 0x7f157d8e9400 in __libc_start_main (/lib64/libc.so.6+0x20400)

Thread T6 created by T0 here:
    #0 0x7f159bae0488 in __interceptor_pthread_create (/lib64/libasan.so.3+0x31488)
    #1 0x55b8eab1d9cb in qemu_thread_create /home/elmarco/src/qq/util/qemu-thread-posix.c:465
    #2 0x55b8ea67874c in migrate_fd_connect /home/elmarco/src/qq/migration/migration.c:2096
    #3 0x55b8ea66cbb0 in migration_channel_connect /home/elmarco/src/qq/migration/migration.c:500
    #4 0x55b8ea678f38 in socket_outgoing_migration /home/elmarco/src/qq/migration/socket.c:87
    #5 0x55b8eaa5a03a in qio_task_complete /home/elmarco/src/qq/io/task.c:142
    #6 0x55b8eaa599cc in gio_task_thread_result /home/elmarco/src/qq/io/task.c:88
    #7 0x7f15823e38e6  (/lib64/libglib-2.0.so.0+0x468e6)
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/elmarco/src/qq/hw/ppc/spapr.c:1528 in htab_save_first_pass

index seems to be wrongly incremented, unless I miss something that
would be worth a comment.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ppc/spapr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 8aecea3..44c26e4 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1524,16 +1524,16 @@ static void htab_save_first_pass(QEMUFile *f, sPAPRMachineState *spapr,
         /* Consume invalid HPTEs */
         while ((index < htabslots)
                && !HPTE_VALID(HPTE(spapr->htab, index))) {
-            index++;
             CLEAN_HPTE(HPTE(spapr->htab, index));
+            index++;
         }
 
         /* Consume valid HPTEs */
         chunkstart = index;
         while ((index < htabslots) && (index - chunkstart < USHRT_MAX)
                && HPTE_VALID(HPTE(spapr->htab, index))) {
-            index++;
             CLEAN_HPTE(HPTE(spapr->htab, index));
+            index++;
         }
 
         if (index > chunkstart) {
-- 
2.9.3

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

* [Qemu-devel] [PULL 2/2] spapr: fix memory hot-unplugging
  2017-03-29  3:34 [Qemu-devel] [PULL 0/2] ppc-for-2.9 queue 20170329 David Gibson
  2017-03-29  3:34 ` [Qemu-devel] [PULL 1/2] spapr: fix buffer-overflow David Gibson
@ 2017-03-29  3:34 ` David Gibson
  2017-03-30 14:27 ` [Qemu-devel] [PULL 0/2] ppc-for-2.9 queue 20170329 Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2017-03-29  3:34 UTC (permalink / raw)
  To: peter.maydell
  Cc: qemu-devel, qemu-ppc, thuth, lvivier, mdroth, aik, agraf,
	David Gibson

From: Laurent Vivier <lvivier@redhat.com>

If, once the kernel has booted, we try to remove a memory
hotplugged while the kernel was not started, QEMU crashes on
an assert:

    qemu-system-ppc64: hw/virtio/vhost.c:651:
                       vhost_commit: Assertion `r >= 0' failed.
    ...
    #4  in vhost_commit
    #5  in memory_region_transaction_commit
    #6  in pc_dimm_memory_unplug
    #7  in spapr_memory_unplug
    #8  spapr_machine_device_unplug
    #9  in hotplug_handler_unplug
    #10 in spapr_lmb_release
    #11 in detach
    #12 in set_allocation_state
    #13 in rtas_set_indicator
    ...

If we take a closer look to the guest kernel log, we can see when
we try to unplug the memory:

    pseries-hotplug-mem: Attempting to hot-add 4 LMB(s)

What happens:

    1- The kernel has ignored the memory hotplug event because
       it was not started when it was generated.

    2- When we hot-unplug the memory,
       QEMU starts to remove the memory,
            generates an hot-unplug event,
        and signals the kernel of the incoming new event

    3- as the kernel is started, on the QEMU signal, it reads
       the event list, decodes the hotplug event and tries to
       finish the hotplugging.

    4- QEMU receive the the hotplug notification while it
       is trying to hot-unplug the memory. This moves the memory
       DRC to an invalid state

This patch prevents this by not allowing to set the allocation
state to USABLE while the DRC is awaiting release.

RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1432382

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ppc/spapr_drc.c         | 20 +++++++++++++++++---
 include/hw/ppc/spapr_drc.h |  1 +
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index 150f6bf..a1cdc87 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -135,6 +135,17 @@ static uint32_t set_allocation_state(sPAPRDRConnector *drc,
         if (!drc->dev) {
             return RTAS_OUT_NO_SUCH_INDICATOR;
         }
+        if (drc->awaiting_release && drc->awaiting_allocation) {
+            /* kernel is acknowledging a previous hotplug event
+             * while we are already removing it.
+             * it's safe to ignore awaiting_allocation here since we know the
+             * situation is predicated on the guest either already having done
+             * so (boot-time hotplug), or never being able to acquire in the
+             * first place (hotplug followed by immediate unplug).
+             */
+            drc->awaiting_allocation_skippable = true;
+            return RTAS_OUT_NO_SUCH_INDICATOR;
+        }
     }
 
     if (drc->type != SPAPR_DR_CONNECTOR_TYPE_PCI) {
@@ -436,9 +447,11 @@ static void detach(sPAPRDRConnector *drc, DeviceState *d,
     }
 
     if (drc->awaiting_allocation) {
-        drc->awaiting_release = true;
-        trace_spapr_drc_awaiting_allocation(get_index(drc));
-        return;
+        if (!drc->awaiting_allocation_skippable) {
+            drc->awaiting_release = true;
+            trace_spapr_drc_awaiting_allocation(get_index(drc));
+            return;
+        }
     }
 
     drc->indicator_state = SPAPR_DR_INDICATOR_STATE_INACTIVE;
@@ -448,6 +461,7 @@ static void detach(sPAPRDRConnector *drc, DeviceState *d,
     }
 
     drc->awaiting_release = false;
+    drc->awaiting_allocation_skippable = false;
     g_free(drc->fdt);
     drc->fdt = NULL;
     drc->fdt_start_offset = 0;
diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h
index fa531d5..5524247 100644
--- a/include/hw/ppc/spapr_drc.h
+++ b/include/hw/ppc/spapr_drc.h
@@ -154,6 +154,7 @@ typedef struct sPAPRDRConnector {
     bool awaiting_release;
     bool signalled;
     bool awaiting_allocation;
+    bool awaiting_allocation_skippable;
 
     /* device pointer, via link property */
     DeviceState *dev;
-- 
2.9.3

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

* Re: [Qemu-devel] [PULL 0/2] ppc-for-2.9 queue 20170329
  2017-03-29  3:34 [Qemu-devel] [PULL 0/2] ppc-for-2.9 queue 20170329 David Gibson
  2017-03-29  3:34 ` [Qemu-devel] [PULL 1/2] spapr: fix buffer-overflow David Gibson
  2017-03-29  3:34 ` [Qemu-devel] [PULL 2/2] spapr: fix memory hot-unplugging David Gibson
@ 2017-03-30 14:27 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2017-03-30 14:27 UTC (permalink / raw)
  To: David Gibson
  Cc: QEMU Developers, qemu-ppc@nongnu.org, Thomas Huth, Laurent Vivier,
	Michael Roth, Alexey Kardashevskiy, Alexander Graf

On 29 March 2017 at 04:34, David Gibson <david@gibson.dropbear.id.au> wrote:
> The following changes since commit df9046363220e57d45818312759b954c033c58ab:
>
>   Update version for v2.9.0-rc2 release (2017-03-28 19:11:16 +0100)
>
> are available in the git repository at:
>
>   git://github.com/dgibson/qemu.git tags/ppc-for-2.9-20170329
>
> for you to fetch changes up to fe6824d12642b005c69123ecf8631f9b13553f8b:
>
>   spapr: fix memory hot-unplugging (2017-03-29 11:35:16 +1100)
>
> ----------------------------------------------------------------
> ppc patch queue for 2017-03-29
>
> Two more bugfixes of sufficient severity to warrant going into 2.9.
>
> ----------------------------------------------------------------
> Laurent Vivier (1):
>       spapr: fix memory hot-unplugging
>
> Marc-André Lureau (1):
>       spapr: fix buffer-overflow
>
>  hw/ppc/spapr.c             |  4 ++--
>  hw/ppc/spapr_drc.c         | 20 +++++++++++++++++---
>  include/hw/ppc/spapr_drc.h |  1 +
>  3 files changed, 20 insertions(+), 5 deletions(-)


Applied, thanks.

-- PMM

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

end of thread, other threads:[~2017-03-30 14:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-29  3:34 [Qemu-devel] [PULL 0/2] ppc-for-2.9 queue 20170329 David Gibson
2017-03-29  3:34 ` [Qemu-devel] [PULL 1/2] spapr: fix buffer-overflow David Gibson
2017-03-29  3:34 ` [Qemu-devel] [PULL 2/2] spapr: fix memory hot-unplugging David Gibson
2017-03-30 14:27 ` [Qemu-devel] [PULL 0/2] ppc-for-2.9 queue 20170329 Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).