From: Jason Wang <jasowang@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Yuri Benditovich <yuri.benditovich@daynix.com>,
qemu-stable@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH for 2.11] virtio-net: don't touch virtqueue if vm is stopped
Date: Mon, 27 Nov 2017 11:26:34 +0800 [thread overview]
Message-ID: <096a9e5b-d622-17d1-2713-764800a11608@redhat.com> (raw)
In-Reply-To: <20171124104447.GA11589@stefanha-x1.localdomain>
On 2017年11月24日 18:44, Stefan Hajnoczi wrote:
> On Fri, Nov 24, 2017 at 10:57:11AM +0800, Jason Wang wrote:
>> On 2017年11月23日 18:59, Stefan Hajnoczi wrote:
>>> On Thu, Nov 23, 2017 at 11:37:46AM +0800, Jason Wang wrote:
>>>> Guest state should not be touched if VM is stopped, unfortunately we
>>>> didn't check running state and tried to drain tx queue unconditionally
>>>> in virtio_net_set_status(). A crash was then noticed as a migration
>>>> destination when user type quit after virtqueue state is loaded but
>>>> before region cache is initialized. In this case,
>>>> virtio_net_drop_tx_queue_data() tries to access the uninitialized
>>>> region cache.
>>>>
>>>> Fix this by only dropping tx queue data when vm is running.
>>> hw/virtio/virtio.c:virtio_load() does the following:
>>>
>>> for (i = 0; i < num; i++) {
>>> if (vdev->vq[i].vring.desc) {
>>> uint16_t nheads;
>>>
>>> /*
>>> * VIRTIO-1 devices migrate desc, used, and avail ring addresses so
>>> * only the region cache needs to be set up. Legacy devices need
>>> * to calculate used and avail ring addresses based on the desc
>>> * address.
>>> */
>>> if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
>>> virtio_init_region_cache(vdev, i);
>>> } else {
>>> virtio_queue_update_rings(vdev, i);
>>> }
>>>
>>> So the region caches should be initialized after virtqueue state is
>>> loaded.
>>>
>>> It's unclear to me which code path triggers this issue. Can you add a
>>> backtrace or an explanation?
>>>
>>> Thanks,
>>> Stefan
>> Migration coroutine was yield before region cache was initialized. The
>> backtrace looks like:
> [...]
>> #16 0x0000555555b1c199 in vmstate_load_state (f=0x555556f7c010,
>> vmsd=0x5555562b8160 <vmstate_virtio>, opaque=0x555557d68610, version_id=1)
>> at migration/vmstate.c:160
>> #17 0x0000555555865cc3 in virtio_load (vdev=0x555557d68610,
>> f=0x555556f7c010, version_id=11) at
>> /home/devel/git/qemu/hw/virtio/virtio.c:2110
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
>
> Thanks for the backtrace! Your patch is fine but I have a larger
> concern:
>
> The backtrace shows that the virtio code is re-entrant during savevm
> load. That's probably a bad thing because set_status() and other APIs
> are probably not intended to run while we are half-way through savevm
> load. The virtqueue is only partially set up at this point :(. I
> wonder if a more general cleanup is necessary to avoid problems like
> this in the future...
>
> Stefan
Yes, this needs some thought. An idea is to guarantee the atomicity of
the virtio state and don't expose partial state. But looks like this
needs lots of changes.
Anyway, I will apply this patch first.
Thanks
next prev parent reply other threads:[~2017-11-27 3:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-23 3:37 [Qemu-devel] [PATCH for 2.11] virtio-net: don't touch virtqueue if vm is stopped Jason Wang
2017-11-23 4:09 ` no-reply
2017-11-23 10:59 ` Stefan Hajnoczi
2017-11-24 2:57 ` Jason Wang
2017-11-24 10:44 ` Stefan Hajnoczi
2017-11-27 3:26 ` Jason Wang [this message]
2017-11-27 11:19 ` Stefan Hajnoczi
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=096a9e5b-d622-17d1-2713-764800a11608@redhat.com \
--to=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=stefanha@redhat.com \
--cc=yuri.benditovich@daynix.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 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).