From: Avi Kivity <avi@qumranet.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: linux-kernel@vger.kernel.org,
Rusty Russell <rusty@rusycorp.com.au>,
virtualization@lists.osdl.org, kvm-devel@lists.sourceforge.net
Subject: Re: [kvm-devel] [PATCH 3/3] virtio PCI device
Date: Tue, 20 Nov 2007 17:01:11 +0200 [thread overview]
Message-ID: <4742F6B7.20503@qumranet.com> (raw)
In-Reply-To: <11944900163817-git-send-email-aliguori@us.ibm.com>
Anthony Liguori wrote:
> This is a PCI device that implements a transport for virtio. It allows virtio
> devices to be used by QEMU based VMMs like KVM or Xen.
>
> +
> +/* the notify function used when creating a virt queue */
> +static void vp_notify(struct virtqueue *vq)
> +{
> + struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
> + struct virtio_pci_vq_info *info = vq->priv;
> +
> + /* we write the queue's selector into the notification register to
> + * signal the other end */
> + iowrite16(info->queue_index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
> +}
>
This means we can't kick multiple queues with one exit.
I'd also like to see a hypercall-capable version of this (but that can
wait).
> +
> +/* A small wrapper to also acknowledge the interrupt when it's handled.
> + * I really need an EIO hook for the vring so I can ack the interrupt once we
> + * know that we'll be handling the IRQ but before we invoke the callback since
> + * the callback may notify the host which results in the host attempting to
> + * raise an interrupt that we would then mask once we acknowledged the
> + * interrupt. */
> +static irqreturn_t vp_interrupt(int irq, void *opaque)
> +{
> + struct virtio_pci_device *vp_dev = opaque;
> + struct virtio_pci_vq_info *info;
> + irqreturn_t ret = IRQ_NONE;
> + u8 isr;
> +
> + /* reading the ISR has the effect of also clearing it so it's very
> + * important to save off the value. */
> + isr = ioread8(vp_dev->ioaddr + VIRTIO_PCI_ISR);
>
Can this be implemented via shared memory? We're exiting now on every
interrupt.
> + return ret;
> +}
> +
> +/* the config->find_vq() implementation */
> +static struct virtqueue *vp_find_vq(struct virtio_device *vdev, unsigned index,
> + bool (*callback)(struct virtqueue *vq))
> +{
> + struct virtio_pci_device *vp_dev = to_vp_device(vdev);
> + struct virtio_pci_vq_info *info;
> + struct virtqueue *vq;
> + int err;
> + u16 num;
> +
> + /* Select the queue we're interested in */
> + iowrite16(index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
>
I would really like to see this implemented as pci config space, with no
tricks like multiplexing several virtqueues on one register. Something
like the PCI BARs where you have all the register numbers allocated
statically to queues.
> +
> + /* Check if queue is either not available or already active. */
> + num = ioread16(vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NUM);
> + if (!num || ioread32(vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN))
> + return ERR_PTR(-ENOENT);
> +
> + /* allocate and fill out our structure the represents an active
> + * queue */
> + info = kmalloc(sizeof(struct virtio_pci_vq_info), GFP_KERNEL);
> + if (!info)
> + return ERR_PTR(-ENOMEM);
> +
> + info->queue_index = index;
> + info->num = num;
> +
> + /* determine the memory needed for the queue and provide the memory
> + * location to the host */
> + info->n_pages = DIV_ROUND_UP(vring_size(num), PAGE_SIZE);
> + info->pages = alloc_pages(GFP_KERNEL | __GFP_ZERO,
> + get_order(info->n_pages));
> + if (info->pages == NULL) {
> + err = -ENOMEM;
> + goto out_info;
> + }
> +
> + /* FIXME: is this sufficient for info->n_pages > 1? */
> + info->queue = kmap(info->pages);
> + if (info->queue == NULL) {
> + err = -ENOMEM;
> + goto out_alloc_pages;
> + }
> +
> + /* activate the queue */
> + iowrite32(page_to_pfn(info->pages),
> + vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
> +
> + /* create the vring */
> + vq = vring_new_virtqueue(info->num, vdev, info->queue,
> + vp_notify, callback);
> + if (!vq) {
> + err = -ENOMEM;
> + goto out_activate_queue;
> + }
> +
> + vq->priv = info;
> + info->vq = vq;
> +
> + spin_lock(&vp_dev->lock);
> + list_add(&info->node, &vp_dev->virtqueues);
> + spin_unlock(&vp_dev->lock);
> +
>
Is this run only on init? If so the lock isn't needed.
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2007-11-20 15:01 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-08 2:46 [PATCH 0/3] virtio PCI driver Anthony Liguori
[not found] ` <11944899922822-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-08 2:46 ` [PATCH 1/3] Export vring functions for modules to use Anthony Liguori
[not found] ` <11944900141678-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-08 2:46 ` [PATCH 2/3] Put the virtio under the virtualization menu Anthony Liguori
[not found] ` <11944900152750-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-08 2:46 ` [PATCH 3/3] virtio PCI device Anthony Liguori
[not found] ` <11944900163817-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-08 6:12 ` Avi Kivity
[not found] ` <4732A8E5.6090307-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-08 13:54 ` Anthony Liguori
[not found] ` <47331531.8070709-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-08 14:37 ` Avi Kivity
[not found] ` <47331F47.70304-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-08 15:06 ` Anthony Liguori
[not found] ` <473325EB.5090907-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-08 15:13 ` Avi Kivity
2007-11-08 23:43 ` Dor Laor
2007-11-08 17:46 ` Arnd Bergmann
[not found] ` <200711081846.36821.arnd-r2nGTMty4D4@public.gmane.org>
2007-11-08 19:04 ` Anthony Liguori
[not found] ` <47335DC6.7090603-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-09 11:03 ` Arnd Bergmann
2007-11-09 0:39 ` Dor Laor
[not found] ` <4733AC3A.20701-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-09 2:17 ` Anthony Liguori
2007-11-20 15:01 ` Avi Kivity [this message]
2007-11-20 15:43 ` [kvm-devel] " Anthony Liguori
[not found] ` <474300AD.4060509-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-20 16:12 ` Avi Kivity
[not found] ` <4743076F.8000105-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-20 22:16 ` Anthony Liguori
[not found] ` <47435CCB.1050506-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-21 7:13 ` Avi Kivity
[not found] ` <4743DAA4.70800-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-21 18:22 ` Zachary Amsden
[not found] ` <1195669377.6352.247.camel-cxY/u30q8FloTgUnLF1by8fTvwmfpRNyZeezCHUQhQ4@public.gmane.org>
2007-11-22 7:32 ` Avi Kivity
2007-11-23 16:51 ` [kvm-devel] " Anthony Liguori
[not found] ` <4747051C.3090903-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-23 17:47 ` Avi Kivity
2007-11-26 19:18 ` [kvm-devel] " Anthony Liguori
[not found] ` <474B1BF3.20901-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-11-27 9:02 ` Avi Kivity
[not found] ` <474BDD28.7050801-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-27 9:09 ` Carsten Otte
[not found] ` <474BDEDE.6060603-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-11-27 9:27 ` [kvm-devel] " Avi Kivity
[not found] ` <474BE319.502-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-27 10:12 ` Carsten Otte
[not found] ` <474BEDAB.3000305-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-11-27 10:19 ` Avi Kivity
[not found] ` <474BEF28.9010005-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-27 10:28 ` Carsten Otte
[not found] ` <474BF157.3080709-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-11-27 13:27 ` [kvm-devel] " Dor Laor
2007-11-27 9:25 ` Arnd Bergmann
2007-11-08 6:49 ` [PATCH 2/3] Put the virtio under the virtualization menu Avi Kivity
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=4742F6B7.20503@qumranet.com \
--to=avi@qumranet.com \
--cc=aliguori@us.ibm.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rusycorp.com.au \
--cc=virtualization@lists.osdl.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).