public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Hollis Blanchard <hollisb@us.ibm.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Anthony Liguori <anthony@codemonkey.ws>, kvm-devel <kvm@vger.kernel.org>
Subject: Re: [BUG] virtio-pci queue allocation not page-aligned
Date: Tue, 02 Dec 2008 16:24:40 -0600	[thread overview]
Message-ID: <1228256680.8128.30.camel@localhost.localdomain> (raw)
In-Reply-To: <200812030835.54164.rusty@rustcorp.com.au>

On Wed, 2008-12-03 at 08:35 +1030, Rusty Russell wrote:
> On Wednesday 03 December 2008 05:38:21 Hollis Blanchard wrote:
> > I just spent a number of hours tracking this one down, and I'm not too
> > thrilled about it. vp_find_vq() does the memory allocation for virtio
> > PCI rings, and it uses kzalloc() to do it. This is bad because the ring
> > memory *must* be page-aligned.
> >
> > According to Anthony, at the time this code was written, various slab
> > allocators were checked and all happened to return page-aligned buffers.
> > So how did I hit a problem? I had enabled CONFIG_SLUB_DEBUG_ON while
> > investigating an unrelated problem, which offset the address by 64
> > bytes.
> >
> > One option is to add a BUG_ON(addr & ~PAGE_MASK) to vp_find_vq(). That's
> > better than nothing, but still stinks.
> 
> It's a bug, we fix it.  I've complained before, but since there was no 
> evidence of it actually breaking, I didn't push.
> 
> Prepare a patch, I'll try to get it in this release.

virtio: ring queues must be page-aligned

kzalloc() does not guarantee page alignment, and in fact this broke when
I enabled CONFIG_SLUB_DEBUG_ON.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
---
Tested with virtio-blk root filesystem.

diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -237,7 +237,8 @@ static struct virtqueue *vp_find_vq(stru
 	info->queue_index = index;
 	info->num = num;
 
-	info->queue = kzalloc(PAGE_ALIGN(vring_size(num)), GFP_KERNEL);
+	info->queue = alloc_pages_exact(PAGE_ALIGN(vring_size(num)),
+	                                GFP_KERNEL|__GFP_ZERO);
 	if (info->queue == NULL) {
 		err = -ENOMEM;
 		goto out_info;


-- 
Hollis Blanchard
IBM Linux Technology Center


      reply	other threads:[~2008-12-02 22:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-02 19:08 [BUG] virtio-pci queue allocation not page-aligned Hollis Blanchard
2008-12-02 19:12 ` Anthony Liguori
2008-12-02 22:05 ` Rusty Russell
2008-12-02 22:24   ` Hollis Blanchard [this message]

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=1228256680.8128.30.camel@localhost.localdomain \
    --to=hollisb@us.ibm.com \
    --cc=anthony@codemonkey.ws \
    --cc=kvm@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /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