From: Stefan Hajnoczi <stefanha@gmail.com>
To: "Sinha, Ani" <Ani.Sinha@tellabs.com>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] virtqueue corruption in emulation mode?
Date: Wed, 28 Sep 2011 17:47:41 +0100 [thread overview]
Message-ID: <CAJSP0QWEgbC9j3vicvzn5pfXm2=MiuK32D1MtqaMzjZg25trVg@mail.gmail.com> (raw)
In-Reply-To: <8C59C829-F5F8-40C8-9012-4E9178C85B35@tellabs.com>
On Wed, Sep 28, 2011 at 3:23 PM, Sinha, Ani <Ani.Sinha@tellabs.com> wrote:
>
> On Sep 28, 2011, at 1:51 AM, Stefan Hajnoczi wrote:
>
>> On Wed, Sep 28, 2011 at 3:01 AM, Sinha, Ani <Ani.Sinha@tellabs.com> wrote:
>>>
>>> On Sep 27, 2011, at 12:17 AM, Stefan Hajnoczi wrote:
>>>
>>>> On Mon, Sep 26, 2011 at 07:16:56PM -0500, Sinha, Ani wrote:
>>>>> I am using the virtqueue (virtqueue_pop, virtqueue_push etc) in the emulated mode (non-kvm mode) from an IO thread (a separate thread different from main QEMU thread). What I am observing is that the virtqueue memory seems to get corrupt. Either qemu crashes while performing virtqueue_push() (virtqueue_push() -> virtqueue_fill() ->bring_used_idx()->lduw_phys()->qemu_get_ram_ptr()->"bad ram offset") or crashes when the guest accesses a bad memory while using virtqueue. Now this never ever happens when I run QEMU in KVM mode (/dev/kvm present) OR when I use my functions from within the main qemu thread. I am unable to figure out why this is happening. I have looked into my code over and over again and I can't seem to explain this behavior. Can any of you guys give me any inkling?
>>>>
>>>> QEMU is not thread-safe in general. It uses a big lock to protect most
>>>> of its internal state.
>>>
>>>
>>> I see. So may be I should do something like qemu_set_fd_handler(fd, …) where fd is a pipe and the handler does the virtqueue_push() etc?
>>> Now my question is, is it safe to do elem = virtqueue_pop(vq) from main event loop, then so some work on the elem popped out in an worker thread and then at some later point do a virtqueue_push(vq, elem) from that handler (which is called by main_loop() ->main_loop_wait())? In other words, the vq reference is being used from the main event loop at two different points from two different functions but not in a contiguous fashion within the same function.
>>
>> Yes but do you need a helper thread? Most of QEMU is based on
>> qemu_set_fd_handler() and callbacks, including for host network and
>> disk I/O. If you follow the way QEMU does things it should be
>> easiest.
>
> I need a helper thread to do blocking IO. The device IOCTLS are inherently blocking, unfortunately.
posix-aio-compat.c already implements a threadpool. It is geared
towards using the QEMU block layer (BlockDriverState) but the pure
ioctl codepath can be used without a BlockDriverState by passing NULL.
So this could save you some effort, check out paio_submit().
Stefan
next prev parent reply other threads:[~2011-09-28 16:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-27 0:16 [Qemu-devel] virtqueue corruption in emulation mode? Sinha, Ani
2011-09-27 7:17 ` Stefan Hajnoczi
2011-09-28 2:01 ` Sinha, Ani
2011-09-28 8:51 ` Stefan Hajnoczi
2011-09-28 14:23 ` Sinha, Ani
2011-09-28 16:47 ` Stefan Hajnoczi [this message]
2011-09-28 18:44 ` Sinha, Ani
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='CAJSP0QWEgbC9j3vicvzn5pfXm2=MiuK32D1MtqaMzjZg25trVg@mail.gmail.com' \
--to=stefanha@gmail.com \
--cc=Ani.Sinha@tellabs.com \
--cc=qemu-devel@nongnu.org \
/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).