Skip to content

Commit

Permalink
virtio-pci queue allocation not page-aligned
Browse files Browse the repository at this point in the history
kzalloc() does not guarantee page alignment, and in fact this broke when
I enabled CONFIG_SLUB_DEBUG_ON.

(Thanks to Anthony Liguori for spotting the missing kfree sub)

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (fixed kfree)
Tested-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
Hollis Blanchard authored and Rusty Russell committed Dec 29, 2008
1 parent 3c92ec8 commit 13b1eb3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/virtio/virtio_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static struct virtqueue *vp_find_vq(struct virtio_device *vdev, unsigned index,
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
struct virtio_pci_vq_info *info;
struct virtqueue *vq;
unsigned long flags;
unsigned long flags, size;
u16 num;
int err;

Expand All @@ -237,7 +237,8 @@ static struct virtqueue *vp_find_vq(struct virtio_device *vdev, unsigned index,
info->queue_index = index;
info->num = num;

info->queue = kzalloc(PAGE_ALIGN(vring_size(num,PAGE_SIZE)), GFP_KERNEL);
size = PAGE_ALIGN(vring_size(num, PAGE_SIZE));
info->queue = alloc_pages_exact(size, GFP_KERNEL|__GFP_ZERO);
if (info->queue == NULL) {
err = -ENOMEM;
goto out_info;
Expand Down Expand Up @@ -266,7 +267,7 @@ static struct virtqueue *vp_find_vq(struct virtio_device *vdev, unsigned index,

out_activate_queue:
iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
kfree(info->queue);
free_pages_exact(info->queue, size);
out_info:
kfree(info);
return ERR_PTR(err);
Expand All @@ -277,7 +278,7 @@ static void vp_del_vq(struct virtqueue *vq)
{
struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
struct virtio_pci_vq_info *info = vq->priv;
unsigned long flags;
unsigned long flags, size;

spin_lock_irqsave(&vp_dev->lock, flags);
list_del(&info->node);
Expand All @@ -289,7 +290,8 @@ static void vp_del_vq(struct virtqueue *vq)
iowrite16(info->queue_index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);

kfree(info->queue);
size = PAGE_ALIGN(vring_size(info->num, PAGE_SIZE));
free_pages_exact(info->queue, size);
kfree(info);
}

Expand Down

0 comments on commit 13b1eb3

Please sign in to comment.