From patchwork Sun Apr 10 08:33:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 696411 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3A8Xtpn029210 for ; Sun, 10 Apr 2011 08:33:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755378Ab1DJIdw (ORCPT ); Sun, 10 Apr 2011 04:33:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10981 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753145Ab1DJIdv (ORCPT ); Sun, 10 Apr 2011 04:33:51 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3A8XhqQ012311 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 10 Apr 2011 04:33:43 -0400 Received: from localhost (vpn2-10-247.sin2.redhat.com [10.67.10.247]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p3A8XeTI026061; Sun, 10 Apr 2011 04:33:42 -0400 Date: Sun, 10 Apr 2011 16:33:39 +0800 From: Amos Kong To: Pekka Enberg Cc: Asias He , Cyrill Gorcunov , Ingo Molnar , kvm@vger.kernel.org Subject: [RFC] [PATCH v2] kvm tools: Make virt_queue__available return false if queue is not initialized. Message-ID: <20110410083339.GC3253@t400> Reply-To: Amos Kong References: <1302411665-5349-1-git-send-email-asias.hejun@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sun, 10 Apr 2011 08:33:55 +0000 (UTC) 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 Signed-off-by: Asias He Signed-off-by: Amos Kong --- 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; }