diff mbox

kvm tools: about using virtio-console

Message ID 20110410033616.GA4899@t400 (mailing list archive)
State New, archived
Headers show

Commit Message

Amos Kong April 10, 2011, 3:36 a.m. UTC
Hi pekka,

Does virtio-console work with kvm-tools?
It seems that virtio-console.vps[] is not initialized in virtio-console.c


(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
#0  0x00000000004026ca in virt_queue__available (vq=0x60d3c8) at include/kvm/virtio.h:31
#1  0x00000000004027f7 in virtio_console__inject_interrupt (self=0x68f010) at virtio-console.c:71
#2  0x00000000004083b2 in handle_sigalrm (sig=14) at kvm-run.c:51
#3  <signal handler called>
#4  0x00007ffff79bf283 in pthread_join () from /lib/libpthread.so.0
#5  0x00000000004088bb in kvm_cmd_run (argc=0, argv=0x7fffffffdd18, prefix=0x0) at kvm-run.c:216
#6  0x000000000040834e in handle_command (command=0x7fffffffdbb0, argc=11, argv=0x7fffffffdd10) at kvm-cmd.c:55
#7  0x0000000000405bd5 in handle_kvm_command (argc=11, argv=0x7fffffffdd10) at main.c:16
#8  0x0000000000405bfe in main (argc=12, argv=0x7fffffffdd08) at main.c:21
(gdb) p *vq
$2 = {vring = {num = 0, desc = 0x0, avail = 0x0, used = 0x0}, pfn = 0, last_avail_idx = 0}

-------

I added the check of vq->vring.avail in virt_queue__available(), but it also failed.

(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 19434)]
  Warning: request type 8

Program received signal SIGFPE, Arithmetic exception.
0x00000000004066cd in virt_queue__pop (queue=0x60d3c8) at include/kvm/virtio.h:21
21              return queue->vring.avail->ring[queue->last_avail_idx++ % queue->vring.num];
(gdb) bt
#0  0x00000000004066cd in virt_queue__pop (queue=0x60d3c8) at include/kvm/virtio.h:21
#1  0x000000000040679c in virt_queue__get_iov (queue=0x60d3c8, iov=0x7fffffffcda0, out=0x7fffffffd5be, in=0x7fffffffd5bc, kvm=0x68f010) at virtio.c:21
#2  0x000000000040284b in virtio_console__inject_interrupt (self=0x68f010) at virtio-console.c:72
#3  0x00000000004083da in handle_sigalrm (sig=14) at kvm-run.c:51
#4  <signal handler called>
#5  0x00007ffff79bf283 in pthread_join () from /lib/libpthread.so.0
#6  0x00000000004088e3 in kvm_cmd_run (argc=0, argv=0x7fffffffdd18, prefix=0x0) at kvm-run.c:216
#7  0x0000000000408376 in handle_command (command=0x7fffffffdbb0, argc=11, argv=0x7fffffffdd10) at kvm-cmd.c:55
#8  0x0000000000405bfd in handle_kvm_command (argc=11, argv=0x7fffffffdd10) at main.c:16
#9  0x0000000000405c26 in main (argc=12, argv=0x7fffffffdd08) at main.c:21
(gdb) p *queue
$2 = {vring = {num = 0, desc = 0x0, avail = 0x0, used = 0x0}, pfn = 0, last_avail_idx = 0}


Amos.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Asias He April 10, 2011, 4:05 a.m. UTC | #1
Hi, Amos

On 04/10/2011 11:36 AM, Amos Kong wrote:
> Hi pekka,
> 
> Does virtio-console work with kvm-tools?
> It seems that virtio-console.vps[] is not initialized in virtio-console.c

I guess you mean virtio-console.vqs[].

They are initialized here in virtio_console_pci_io_out when guest pings us.
case VIRTIO_PCI_QUEUE_PFN: {
        struct virt_queue *queue;
        void *p;

        assert(console_device.queue_selector < VIRTIO_CONSOLE_NUM_QUEUES);

        queue           =
&console_device.vqs[console_device.queue_selector];
        queue->pfn      = ioport__read32(data);
        p               = guest_flat_to_host(self, queue->pfn << 12);

        vring_init(&queue->vring, VIRTIO_CONSOLE_QUEUE_SIZE, p, 4096);

        break;
}

However, virtio_console__inject_interrupt tries to use virt queues
before guest tell us to initialize them. I think that's why you got
SIGSEGV and SIGFPE.

Good catch! I am gonna fix it.


> 
> 
> (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
> #0  0x00000000004026ca in virt_queue__available (vq=0x60d3c8) at include/kvm/virtio.h:31
> #1  0x00000000004027f7 in virtio_console__inject_interrupt (self=0x68f010) at virtio-console.c:71
> #2  0x00000000004083b2 in handle_sigalrm (sig=14) at kvm-run.c:51
> #3  <signal handler called>
> #4  0x00007ffff79bf283 in pthread_join () from /lib/libpthread.so.0
> #5  0x00000000004088bb in kvm_cmd_run (argc=0, argv=0x7fffffffdd18, prefix=0x0) at kvm-run.c:216
> #6  0x000000000040834e in handle_command (command=0x7fffffffdbb0, argc=11, argv=0x7fffffffdd10) at kvm-cmd.c:55
> #7  0x0000000000405bd5 in handle_kvm_command (argc=11, argv=0x7fffffffdd10) at main.c:16
> #8  0x0000000000405bfe in main (argc=12, argv=0x7fffffffdd08) at main.c:21
> (gdb) p *vq
> $2 = {vring = {num = 0, desc = 0x0, avail = 0x0, used = 0x0}, pfn = 0, last_avail_idx = 0}
> 
> -------
> 
> I added the check of vq->vring.avail in virt_queue__available(), but it also failed.
> 
> diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
> index 9f892a1..d3622b1 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 -1;
>         return vq->vring.avail->idx !=  vq->last_avail_idx;
>  }
> 
> (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 19434)]
>   Warning: request type 8
> 
> Program received signal SIGFPE, Arithmetic exception.
> 0x00000000004066cd in virt_queue__pop (queue=0x60d3c8) at include/kvm/virtio.h:21
> 21              return queue->vring.avail->ring[queue->last_avail_idx++ % queue->vring.num];
> (gdb) bt
> #0  0x00000000004066cd in virt_queue__pop (queue=0x60d3c8) at include/kvm/virtio.h:21
> #1  0x000000000040679c in virt_queue__get_iov (queue=0x60d3c8, iov=0x7fffffffcda0, out=0x7fffffffd5be, in=0x7fffffffd5bc, kvm=0x68f010) at virtio.c:21
> #2  0x000000000040284b in virtio_console__inject_interrupt (self=0x68f010) at virtio-console.c:72
> #3  0x00000000004083da in handle_sigalrm (sig=14) at kvm-run.c:51
> #4  <signal handler called>
> #5  0x00007ffff79bf283 in pthread_join () from /lib/libpthread.so.0
> #6  0x00000000004088e3 in kvm_cmd_run (argc=0, argv=0x7fffffffdd18, prefix=0x0) at kvm-run.c:216
> #7  0x0000000000408376 in handle_command (command=0x7fffffffdbb0, argc=11, argv=0x7fffffffdd10) at kvm-cmd.c:55
> #8  0x0000000000405bfd in handle_kvm_command (argc=11, argv=0x7fffffffdd10) at main.c:16
> #9  0x0000000000405c26 in main (argc=12, argv=0x7fffffffdd08) at main.c:21
> (gdb) p *queue
> $2 = {vring = {num = 0, desc = 0x0, avail = 0x0, used = 0x0}, pfn = 0, last_avail_idx = 0}
> 
> 
> Amos.
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
diff mbox

Patch

diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
index 9f892a1..d3622b1 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 -1;
        return vq->vring.avail->idx !=  vq->last_avail_idx;
 }