All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Stefan Hajnoczi" <stefanha@gmail.com>,
	"Fernando Casas Schössow" <casasfernando@outlook.com>
Cc: Natanael Copa <ncopa@alpinelinux.org>,
	Richard Henderson <rth@twiddle.net>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [Qemu-block] Guest unresponsive after Virtqueue size exceeded error
Date: Fri, 22 Feb 2019 15:38:44 +0100	[thread overview]
Message-ID: <01ad59eb-6548-27cd-f192-91819e929dbc@redhat.com> (raw)
In-Reply-To: <CAJSP0QWouR43wVi0guTuASP9gc24_CPucbBvtfE5_htkDkmsrQ@mail.gmail.com>

On 22/02/19 15:04, Stefan Hajnoczi wrote:
> On Fri, Feb 22, 2019 at 12:57 PM Fernando Casas Schössow
> <casasfernando@outlook.com> wrote:
> 
> I have CCed Natanael Copa, qemu package maintainer in Alpine Linux.
> 
> Fernando: Can you confirm that the bug occurs with an unmodified
> Alpine Linux qemu binary?

I can confirm that the memcpy calls are there, at least.

Paolo

> Richard: Commit 7db2145a6826b14efceb8dd64bfe6ad8647072eb ("bswap: Add
> host endian unaligned access functions") introduced the unaligned
> memory access functions in question here.  Please see below for
> details on the bug - basically QEMU code assumes they are atomic, but
> that is not guaranteed :(.  Any ideas for how to fix this?
> 
> Natanael: It seems likely that the qemu package in Alpine Linux
> suffers from a compilation issue resulting in a broken QEMU.  It may
> be necessary to leave the compiler optimization flag alone in APKBUILD
> to work around this problem.
> 
> Here are the details.  QEMU relies on the compiler turning
> memcpy(&dst, &src, 2) turning into a load instruction in
> include/qemu/bswap.h:lduw_he_p() (explanation below):
> 
> /* Any compiler worth its salt will turn these memcpy into native unaligned
>    operations.  Thus we don't need to play games with packed attributes, or
>    inline byte-by-byte stores.  */
> 
> static inline int lduw_he_p(const void *ptr)
> {
>     uint16_t r;
>     memcpy(&r, ptr, sizeof(r));
>     return r;
> }
> 
> Here is the disassembly snippet of virtqueue_pop() from Fedora 29 that
> shows the load instruction:
> 
>   398166:       0f b7 42 02             movzwl 0x2(%rdx),%eax
>   39816a:       66 89 43 32             mov    %ax,0x32(%rbx)
> 
> Here is the instruction sequence in the Alpine Linux binary:
> 
>   455562:    ba 02 00 00 00           mov    $0x2,%edx
>   455567:    e8 74 24 f3 ff           callq  3879e0 <memcpy@plt>
>   45556c:    0f b7 44 24 42           movzwl 0x42(%rsp),%eax
>   455571:    66 41 89 47 32           mov    %ax,0x32(%r15)
> 
> It's calling memcpy instead of using a load instruction.
> 
> Fernando found that QEMU's virtqueue_pop() function sees bogus values
> when loading a 16-bit guest RAM location.  Paolo figured out that the
> bogus value can be produced by memcpy() when another thread is
> updating the 16-bit memory location simultaneously.  This is a race
> condition between one thread loading the 16-bit value and another
> thread storing it (in this case a guest vcpu thread).  Sometimes
> memcpy() may load one old byte and one new byte, resulting in a bogus
> value.
> 
> The symptom that Fernando experienced is a "Virtqueue size exceeded"
> error message from QEMU and then the virtio-blk or virtio-scsi device
> stops working.  This issue potentially affects other device emulation
> code in QEMU as well, not just virtio devices.
> 
> For the time being, I suggest tweaking the APKBUILD so the memcpy() is
> not generated.  Hopefully QEMU can make the code more portable in the
> future so the compiler always does the expected thing, but this may
> not be easily possible.
> 
> Stefan
> 

  reply	other threads:[~2019-02-22 14:39 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-14 21:56 [Qemu-devel] Guest unresponsive after Virtqueue size exceeded error Fernando Casas Schössow
2017-06-16  6:58 ` Ladi Prosek
2017-06-16 10:11   ` Fernando Casas Schössow
2017-06-16 10:25     ` Ladi Prosek
2017-06-19 22:10       ` Fernando Casas Schössow
2017-06-20  5:59         ` Ladi Prosek
2017-06-20  6:30           ` Fernando Casas Schössow
2017-06-20  7:52             ` Ladi Prosek
2017-06-21 12:19               ` Fernando Casas Schössow
2017-06-22  7:43                 ` Ladi Prosek
2017-06-23  6:29                   ` Fernando Casas Schössow
     [not found]                   ` <1498199343.2815.0@smtp-mail.outlook.com>
2017-06-24  8:34                     ` Fernando Casas Schössow
2019-01-31 11:32                       ` Fernando Casas Schössow
2019-02-01  5:48                         ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2019-02-01  8:17                           ` Fernando Casas Schössow
2019-02-04  6:06                             ` Stefan Hajnoczi
2019-02-04  7:24                               ` Fernando Casas Schössow
     [not found]                                 ` <AM5PR0602MB32368CB5ADDEC05F42D8BC8FA46D0@AM5PR0602MB3236.eurprd06.prod.outlo ok.com>
2019-02-06  7:15                                   ` Fernando Casas Schössow
     [not found]                                 ` <AM5PR0602MB32368CB5ADDEC05F42D8BC8FA46D0@AM5PR0602MB3236.eurprd06.prod.outlo>
     [not found]                                   ` <VI1PR0602MB3245032D51A5DF45AF6E1952A46F0@VI1PR0602MB3245.eurprd06.prod.outlo ok.com>
2019-02-06 16:47                                     ` Fernando Casas Schössow
2019-02-11  3:17                                       ` Stefan Hajnoczi
2019-02-11  9:48                                         ` Fernando Casas Schössow
2019-02-18  7:21                                         ` Fernando Casas Schössow
     [not found]                                           ` <VI1PR0602MB3245424120D151F29884A7E2A4630@VI1PR0602MB3245.eurprd06.prod.outlo ok.com>
2019-02-19  7:26                                             ` Fernando Casas Schössow
2019-02-20 16:58                                           ` Stefan Hajnoczi
2019-02-20 17:53                                             ` Paolo Bonzini
2019-02-20 18:56                                               ` Fernando Casas Schössow
2019-02-21 11:11                                                 ` Stefan Hajnoczi
2019-02-21 11:33                                                   ` Fernando Casas Schössow
     [not found]                                                   ` <VI1PR0602MB3245593855B029B427ED544FA47E0@VI1PR0602MB3245.eurprd06.prod.outlook.com>
     [not found]                                                     ` <CAJSP0QUs9Yz2-k1KyVMwpgx6RwY9cK7qdQRCQ74xmgXJPJR-qw@mail.gmail.com>
     [not found]                                                       ` <VI1PR0602MB32453A8B5CBC0308C7D18F1DA47E0@VI1PR0602MB3245.eurprd06.prod.outlook.com>
     [not found]                                                         ` <CAJSP0QVxaW3tezjBN9owJHsxzE9h8_qcaeRr5zHHKxKJOeFnkQ@mail.gmail.com>
     [not found]                                                           ` <CAJSP0QVXoZJ9MJ0qp4RM_m2fGJ8iFSyJMAU_X7mdiQvpOK59KA@mail.gmail.com>
     [not found]                                                             ` <VI1PR0602MB324516419266A934FE7759C6A47E0@VI1PR0602MB3245.eurprd06.prod.outlook.com>
     [not found]                                                               ` <VI1PR0602MB324516419266A934FE7759C6A47E0@VI1PR0602MB3245.eurprd06.prod.outlo>
     [not found]                                                                 ` <VI1PR0602MB32454C17192EFA863E29CC49A47E0@VI1PR0602MB3245.eurprd06.prod.outlo>
     [not found]                                                                   ` <VI1PR0602MB324547F72DA9EDEB1613C888A47E0@VI1PR0602MB3245.eurprd06.prod.outlook.com>
     [not found]                                                                     ` <CAJSP0QUg=cq3tCSLidQ9BR2hxAo3K6gA6LKtpx5Rjb=_6XgJ6Q@mail.gmail.com>
     [not found]                                                                       ` <28e6b4ed-9afd-3a79-6267-86c7385c23ce@redhat.com>
     [not found]                                                                         ` <VI1PR0602MB324578F91F1AF9390D03022FA47F0@VI1PR0602MB3245.eurprd06.prod.outlook.com>
2019-02-22 14:04                                                                           ` Stefan Hajnoczi
2019-02-22 14:38                                                                             ` Paolo Bonzini [this message]
2019-02-22 14:43                                                                             ` Fernando Casas Schössow
2019-02-22 14:55                                                                               ` Paolo Bonzini
2019-02-22 15:48                                                                                 ` Fernando Casas Schössow
2019-02-22 16:37                                                                             ` Dr. David Alan Gilbert
2019-02-22 16:39                                                                               ` Paolo Bonzini
2019-02-22 16:47                                                                                 ` Dr. David Alan Gilbert
2019-02-23 11:49                                                                             ` Natanael Copa
2019-02-26 13:30                                                                               ` Paolo Bonzini
2019-02-28  7:35                                                                                 ` Fernando Casas Schössow
2019-02-23 15:55                                                                             ` Natanael Copa
2019-02-23 16:18                                                                               ` Peter Maydell
2019-02-25 10:24                                                                                 ` Natanael Copa
2019-02-25 10:34                                                                                   ` Peter Maydell
2019-02-25 12:15                                                                                     ` Fernando Casas Schössow
2019-02-25 12:21                                                                                     ` Natanael Copa
2019-02-25 13:06                                                                                       ` Peter Maydell
2019-02-25 13:25                                                                                         ` Natanael Copa
2019-02-25 13:32                                                                                           ` Fernando Casas Schössow
     [not found]                                                                                             ` <VI1PR0602MB3245A6B693B23DA2E0E8E500A47A0@VI1PR0602MB3245.eurprd06.prod.outlo ok.com>
2019-02-25 15:41                                                                                               ` Fernando Casas Schössow
2019-02-28  9:58                                                                                         ` Peter Maydell
2019-03-07  7:14                                                                                           ` Fernando Casas Schössow
2019-02-23 16:21                                                                               ` Fernando Casas Schössow
2019-02-25 10:30                                                                               ` Stefan Hajnoczi
2019-02-25 10:33                                                                                 ` Stefan Hajnoczi
2019-02-23 16:57                                                                             ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01ad59eb-6548-27cd-f192-91819e929dbc@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=casasfernando@outlook.com \
    --cc=ncopa@alpinelinux.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.