1. 22 3月, 2016 22 次提交
    • M
      ivshmem: Propagate errors through ivshmem_recv_setup() · 1309cf44
      Markus Armbruster 提交于
      This kills off the funny state described in the previous commit.
      
      Simplify ivshmem_io_read() accordingly, and update documentation.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1458066895-20632-27-git-send-email-armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      1309cf44
    • M
      ivshmem: Receive shared memory synchronously in realize() · 3a55fc0f
      Markus Armbruster 提交于
      When configured for interrupts (property "chardev" given), we receive
      the shared memory from an ivshmem server.  We do so asynchronously
      after realize() completes, by setting up callbacks with
      qemu_chr_add_handlers().
      
      Keeping server I/O out of realize() that way avoids delays due to a
      slow server.  This is probably relevant only for hot plug.
      
      However, this funny "no shared memory, yet" state of the device also
      causes a raft of issues that are hard or impossible to work around:
      
      * The guest is exposed to this state: when we enter and leave it its
        shared memory contents is apruptly replaced, and device register
        IVPosition changes.
      
        This is a known issue.  We document that guests should not access
        the shared memory after device initialization until the IVPosition
        register becomes non-negative.
      
        For cold plug, the funny state is unlikely to be visible in
        practice, because we normally receive the shared memory long before
        the guest gets around to mess with the device.
      
        For hot plug, the timing is tighter, but the relative slowness of
        PCI device configuration has a good chance to hide the funny state.
      
        In either case, guests complying with the documented procedure are
        safe.
      
      * Migration becomes racy.
      
        If migration completes before the shared memory setup completes on
        the source, shared memory contents is silently lost.  Fortunately,
        migration is rather unlikely to win this race.
      
        If the shared memory's ramblock arrives at the destination before
        shared memory setup completes, migration fails.
      
        There is no known way for a management application to wait for
        shared memory setup to complete.
      
        All you can do is retry failed migration.  You can improve your
        chances by leaving more time between running the destination QEMU
        and the migrate command.
      
        To mitigate silent memory loss, you need to ensure the server
        initializes shared memory exactly the same on source and
        destination.
      
        These issues are entirely undocumented so far.
      
      I'd expect the server to be almost always fast enough to hide these
      issues.  But then rare catastrophic races are in a way the worst kind.
      
      This is way more trouble than I'm willing to take from any device.
      Kill the funny state by receiving shared memory synchronously in
      realize().  If your hot plug hangs, go kill your ivshmem server.
      
      For easier review, this commit only makes the receive synchronous, it
      doesn't add the necessary error propagation.  Without that, the funny
      state persists.  The next commit will do that, and kill it off for
      real.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-26-git-send-email-armbru@redhat.com>
      3a55fc0f
    • M
      ivshmem: Plug leaks on unplug, fix peer disconnect · 9db51b4d
      Markus Armbruster 提交于
      close_peer_eventfds() cleans up three things: ioeventfd triggers if
      they exist, eventfds, and the array to store them.
      
      Commit 98609cd8 (v1.2.0) fixed it not to clean up ioeventfd triggers
      when they don't exist (property ioeventfd=off, which is the default).
      Unfortunately, the fix also made it skip cleanup of the eventfds and
      the array then.  This is a memory and file descriptor leak on unplug.
      
      Additionally, the reset of nb_eventfds is skipped.  Doesn't matter on
      unplug.  On peer disconnect, however, this permanently wedges the
      interrupt vectors used for that peer's ID.  The eventfds stay behind,
      but aren't connected to a peer anymore.  When the ID gets recycled for
      a new peer, the new peer's eventfds get assigned to vectors after the
      old ones.  Commonly, the device's number of vectors matches the
      server's, so the new ones get dropped with a "Too many eventfd
      received" message.  Interrupts either don't work (common case) or go
      to the wrong vector.
      
      Fix by narrowing the conditional to just the ioeventfd trigger
      cleanup.
      
      While there, move the "invalid" peer check to the only caller where it
      can actually happen, and tighten it to reject own ID.
      
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-25-git-send-email-armbru@redhat.com>
      9db51b4d
    • M
      ivshmem: Disentangle ivshmem_read() · ca0b7566
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-24-git-send-email-armbru@redhat.com>
      ca0b7566
    • M
      ivshmem: Simplify rejection of invalid peer ID from server · cd9953f7
      Markus Armbruster 提交于
      ivshmem_read() processes server messages.  These are 64 bit signed
      integers.  -1 is shared memory setup, 16 bit unsigned is a peer ID,
      anything else is invalid.
      
      ivshmem_read() rejects invalid negative messages right away, silently.
      
      Invalid positive messages get rejected only in resize_peers(), and
      ivshmem_read() then prints the rather cryptic message "failed to
      resize peers array".
      
      Extend the first check to cover all invalid messages, make it report
      "server sent invalid message", and drop the second check.
      
      Now resize_peers() can't fail anymore; simplify.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-23-git-send-email-armbru@redhat.com>
      cd9953f7
    • M
      ivshmem: Assert interrupts are set up once · 3c27969b
      Markus Armbruster 提交于
      An interrupt is set up when the interrupt's file descriptor is
      received.  Each message applies to the next interrupt vector.
      Therefore, each vector cannot be set up more than once.
      
      ivshmem_add_kvm_msi_virq() half-heartedly tries not to rely on this by
      doing nothing then, but that's not going to recover from this error
      should it become possible in the future.  watch_vector_notifier()
      doesn't even try.
      
      Simply assert what is the case, so we get alerted if we ever screw it
      up.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-22-git-send-email-armbru@redhat.com>
      3c27969b
    • M
      ivshmem: Leave INTx alone when using MSI-X · 2d1d422d
      Markus Armbruster 提交于
      The ivshmem device can either use MSI-X or legacy INTx for interrupts.
      
      With MSI-X enabled, peer interrupt events trigger an MSI as they
      should.  But software can still raise INTx via interrupt status and
      mask register in BAR 0.  This is explicitly prohibited by PCI Local
      Bus Specification Revision 3.0, section 6.8.3.3:
      
          While enabled for MSI or MSI-X operation, a function is prohibited
          from using its INTx# pin (if implemented) to request service (MSI,
          MSI-X, and INTx# are mutually exclusive).
      
      Fix the device model to leave INTx alone when using MSI-X.
      
      Document that we claim to use INTx in config space even when we don't.
      Unlike other devices, ivshmem does *not* use INTx when configured for
      MSI-X and MSI-X isn't enabled by software.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <1458066895-20632-21-git-send-email-armbru@redhat.com>
      2d1d422d
    • M
      ivshmem: Clean up MSI-X conditions · 082751e8
      Markus Armbruster 提交于
      There are three predicates related to MSI-X:
      
      * ivshmem_has_feature(s, IVSHMEM_MSI) is true unless the non-MSI-X
        variant of the device is selected with msi=off.
      
      * msix_present() is true when the device has the PCI capability MSI-X.
        It's initially false, and becomes true during successful realize of
        the MSI-X variant of the device.  Thus, it's the same as
        ivshmem_has_feature(s, IVSHMEM_MSI) for realized devices.
      
      * msix_enabled() is true when msix_present() is true and guest software
        has enabled MSI-X.
      
      Code that differs between the non-MSI-X and the MSI-X variant of the
      device needs to be guarded by ivshmem_has_feature(s, IVSHMEM_MSI) or
      by msix_present(), except the latter works only for realized devices.
      
      Code that depends on whether MSI-X is in use needs to be guarded with
      msix_enabled().
      
      Code review led me to two minor messes:
      
      * ivshmem_vector_notify() calls msix_notify() even when
        !msix_enabled(), unlike most other MSI-X-capable devices.  As far as
        I can tell, msix_notify() does nothing when !msix_enabled().  Add
        the guard anyway.
      
      * Most callers of ivshmem_use_msix() guard it with
        ivshmem_has_feature(s, IVSHMEM_MSI).  Not necessary, because
        ivshmem_use_msix() does nothing when !msix_present().  That's
        ivshmem's only use of msix_present(), though.  Guard it
        consistently, and drop the now redundant msix_present() check.
        While there, rename ivshmem_use_msix() to ivshmem_msix_vector_use().
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1458066895-20632-20-git-send-email-armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      082751e8
    • M
      ivshmem: Clean up register callbacks · 434ad76d
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-19-git-send-email-armbru@redhat.com>
      434ad76d
    • M
      ivshmem: Failed realize() can leave migration blocker behind · d855e275
      Markus Armbruster 提交于
      If pci_ivshmem_realize() fails after it created its migration blocker,
      the blocker is left in place.  Fix that by creating it last.
      
      Likewise, if it fails after it called fifo8_create(), it leaks fifo
      memory.  Fix that the same way.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-18-git-send-email-armbru@redhat.com>
      d855e275
    • M
      ivshmem: Fix harmless misuse of Error · 9cf70c52
      Markus Armbruster 提交于
      We reuse errp after passing it host_memory_backend_get_memory().  If
      both host_memory_backend_get_memory() and the reuse set an error, the
      reuse will fail the assertion in error_setv().  Fortunately,
      host_memory_backend_get_memory() can't fail.
      
      Pass it &error_abort to make our assumption explicit, and to get the
      assertion failure in the right place should it become invalid.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-17-git-send-email-armbru@redhat.com>
      9cf70c52
    • M
      ivshmem: Don't destroy the chardev on version mismatch · 71c26581
      Markus Armbruster 提交于
      Yes, the chardev is commonly useless after we read a bad version from
      it, but destroying it is inappropriate anyway: the user created it, so
      the user should be able to hold on to it as long as he likes.  We
      don't destroy it on other errors.  Screwed up in commit 5105b1d8.
      
      Stop reading instead.
      
      Also note QEMU's behavior in ivshmem-spec.txt.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-16-git-send-email-armbru@redhat.com>
      71c26581
    • M
      ivshmem: Drop ivshmem_event() stub · c20fc0c3
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-15-git-send-email-armbru@redhat.com>
      c20fc0c3
    • M
      ivshmem: Clean up after commit 9940c323 · e64befe9
      Markus Armbruster 提交于
      IVShmemState member eventfd_chr is useless since commit 9940c323.  Drop
      it.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-14-git-send-email-armbru@redhat.com>
      e64befe9
    • M
      ivshmem: Compile debug prints unconditionally to prevent bit-rot · a4fa93bf
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-13-git-send-email-armbru@redhat.com>
      a4fa93bf
    • M
      ivshmem: Add missing newlines to debug printfs · 97553976
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-12-git-send-email-armbru@redhat.com>
      97553976
    • M
      ivshmem: Rewrite specification document · fdee2025
      Markus Armbruster 提交于
      This started as an attempt to update ivshmem_device_spec.txt for
      clarity, accuracy and completeness while working on its code, and
      quickly became a full rewrite.  Since the diff would be useless
      anyway, I'm using the opportunity to rename the file to
      ivshmem-spec.txt.
      
      I tried hard to ensure the new text contradicts neither the old text
      nor the code.  If the new text contradicts the old text but not the
      code, it's probably a bug in the old text.  If the new text
      contradicts both, its probably a bug in the new text.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-11-git-send-email-armbru@redhat.com>
      fdee2025
    • M
      ivshmem-test: Improve test cases /ivshmem/server-* · 41b65e5e
      Markus Armbruster 提交于
      Document missing test: behavior with MSI-X present but not enabled.
      
      For MSI-X, we test and clear the interrupt pending bit before testing
      the interrupt.  For INTx, we only clear.  Change to test and clear for
      consistency.
      
      Test MSI-X vector 1 in addition to vector 0.
      
      Improve comments.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-10-git-send-email-armbru@redhat.com>
      41b65e5e
    • M
      ivshmem-test: Clean up wait for devices to become operational · 14c5d49a
      Markus Armbruster 提交于
      test_ivshmem_server() waits until the first byte in BAR 2 contains the
      0x42 we put into shared memory.  Works because the byte reads zero
      until the device maps the shared memory gotten from the server.
      
      Check the IVPosition register instead: it's initially -1, and becomes
      non-negative right when the device maps the share memory, so no
      change, just cleaner, because it's what guest software is supposed to
      do.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-9-git-send-email-armbru@redhat.com>
      14c5d49a
    • M
      ivshmem-test: Improve test case /ivshmem/single · 4958fe5d
      Markus Armbruster 提交于
      Test state of registers after reset.
      
      Test reading Interrupt Status clears it.
      
      Test (invalid) read of Doorbell.
      
      Add more comments.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-8-git-send-email-armbru@redhat.com>
      4958fe5d
    • M
      tests/libqos/pci-pc: Fix qpci_pc_iomap() to map BARs aligned · 99826172
      Markus Armbruster 提交于
      qpci_pc_iomap() maps BARs one after the other, without padding.  This
      is wrong.  PCI Local Bus Specification Revision 3.0, 6.2.5.1. Address
      Maps: "all address spaces used are a power of two in size and are
      naturally aligned".  That's because the size of a BAR is given by the
      number of address bits the device decodes, and the BAR needs to be
      mapped at a multiple of that size to ensure the address decoding
      works.
      
      Fix qpci_pc_iomap() accordingly.  This takes care of a FIXME in
      ivshmem-test.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1458066895-20632-7-git-send-email-armbru@redhat.com>
      99826172
    • M
      event_notifier: Make event_notifier_init_fd() #ifdef CONFIG_EVENTFD · 330b5836
      Markus Armbruster 提交于
      Event notifiers are designed for eventfd(2).  They can fall back to
      pipes, but according to Paolo, event_notifier_init_fd() really
      requires the real thing, and should therefore be under #ifdef
      CONFIG_EVENTFD.  Do that.
      
      Its only user is ivshmem, which is currently CONFIG_POSIX.  Narrow it
      to CONFIG_EVENTFD.
      
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <1458066895-20632-6-git-send-email-armbru@redhat.com>
      330b5836
  2. 19 3月, 2016 4 次提交
  3. 17 3月, 2016 14 次提交