From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hollis Blanchard Subject: Re: [BUG] virtio-pci queue allocation not page-aligned Date: Tue, 02 Dec 2008 16:24:40 -0600 Message-ID: <1228256680.8128.30.camel@localhost.localdomain> References: <1228244901.8128.13.camel@localhost.localdomain> <200812030835.54164.rusty@rustcorp.com.au> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: Anthony Liguori , kvm-devel To: Rusty Russell Return-path: Received: from e5.ny.us.ibm.com ([32.97.182.145]:38151 "EHLO e5.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752369AbYLBWYm (ORCPT ); Tue, 2 Dec 2008 17:24:42 -0500 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e5.ny.us.ibm.com (8.13.1/8.13.1) with ESMTP id mB2MOHVv018644 for ; Tue, 2 Dec 2008 17:24:17 -0500 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id mB2MOfnq163894 for ; Tue, 2 Dec 2008 17:24:41 -0500 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id mB2MOfix000997 for ; Tue, 2 Dec 2008 17:24:41 -0500 In-Reply-To: <200812030835.54164.rusty@rustcorp.com.au> Sender: kvm-owner@vger.kernel.org List-ID: 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 --- 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