public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: Asias He <asias.hejun@gmail.com>,
	Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>,
	kvm@vger.kernel.org
Subject: [RFC] [PATCH v2] kvm tools: Make virt_queue__available return false if queue is not initialized.
Date: Sun, 10 Apr 2011 16:33:39 +0800	[thread overview]
Message-ID: <20110410083339.GC3253@t400> (raw)
In-Reply-To: <BANLkTi=LR6NXqipSzzzPD-UcxX9AaVX-1Q@mail.gmail.com>


virtio_console__inject_interrupt tries to use virt queues before guest
tell us to initialize them.

(gdb) r run -i linux-0.2.img -k ./vmlinuz-2.6.38-rc6+ -r ./initrd.img-2.6.38-rc6+ -p=init=1 -m 500 -c
Starting program: /project/rh/kvm-tools/tools/kvm/kvm run -i linux-0.2.img -k ./vmlinuz-2.6.38-rc6+ -r ./initrd.img-2.6.38-rc6+ -p=init=1 -m 500 -c
[Thread debugging using libthread_db enabled]
[New Thread 0x7fffd6e2d700 (LWP 19280)]
  Warning: request type 8

Program received signal SIGSEGV, Segmentation fault.
0x00000000004026ca in virt_queue__available (vq=0x60d3c8) at include/kvm/virtio.h:31
31              return vq->vring.avail->idx !=  vq->last_avail_idx;
(gdb)
(gdb) bt
(gdb) p *vq
$2 = {vring = {num = 0, desc = 0x0, avail = 0x0, used = 0x0}, pfn = 0, last_avail_idx = 0}

include/kvm/virtio-console.h:
 59 void virtio_console__inject_interrupt(struct kvm *self)
....
 71         if (term_readable(CONSOLE_VIRTIO) && virt_queue__available(vq)) {
 72                 head = virt_queue__get_iov(vq, iov, &out, &in, self);
                           ^^^^ then this block will not be executed if
                                virtio_queue is unavaiable.


Changes from v1:
- move the check of virt_queue out of virt_queue__get_iov()

Reported-by: Amos Kong <akong@redhat.com>
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Amos Kong <akong@redhat.com>

---
 tools/kvm/include/kvm/virtio.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
index 9f892a1..c8ff376 100644
--- a/tools/kvm/include/kvm/virtio.h
+++ b/tools/kvm/include/kvm/virtio.h
@@ -28,6 +28,8 @@ static inline struct vring_desc *virt_queue__get_desc(struct virt_queue *queue,
 
 static inline bool virt_queue__available(struct virt_queue *vq)
 {
+        if (!vq->vring.avail)
+		 return 0;
 	return vq->vring.avail->idx !=  vq->last_avail_idx;
 }
 
-- 
1.7.1


  parent reply	other threads:[~2011-04-10  8:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-10  5:01 [PATCH] kvm tools: Make virt_queue__available return false if queue is not initialized Asias He
2011-04-10  7:04 ` Pekka Enberg
2011-04-10  8:27   ` Amos Kong
2011-04-10  8:33   ` Amos Kong [this message]
2011-04-10  8:44     ` [RFC] [PATCH v2] " Pekka Enberg

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=20110410083339.GC3253@t400 \
    --to=akong@redhat.com \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.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