From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3iOC-0005JH-1X for qemu-devel@nongnu.org; Tue, 01 Dec 2015 05:42:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a3iO7-0000Ur-Q3 for qemu-devel@nongnu.org; Tue, 01 Dec 2015 05:42:27 -0500 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:58085) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3iO7-0000UR-I7 for qemu-devel@nongnu.org; Tue, 01 Dec 2015 05:42:23 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Dec 2015 10:42:22 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 0E6912190056 for ; Tue, 1 Dec 2015 10:42:12 +0000 (GMT) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tB1AgIhs3932650 for ; Tue, 1 Dec 2015 10:42:18 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tB19gJ4J021913 for ; Tue, 1 Dec 2015 02:42:19 -0700 Date: Tue, 1 Dec 2015 11:42:15 +0100 From: Greg Kurz Message-ID: <20151201114215.1efdf42a@bahia.local> In-Reply-To: <20151130151039-mutt-send-email-mst@redhat.com> References: <20151130105044.12269.21261.stgit@bahia.huguette.org> <565C2AB5.7050008@redhat.com> <20151130151039-mutt-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] mmap-alloc: use same backend for all mappings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Paolo Bonzini , qemu-devel@nongnu.org On Mon, 30 Nov 2015 15:12:08 +0200 "Michael S. Tsirkin" wrote: > On Mon, Nov 30, 2015 at 11:53:41AM +0100, Paolo Bonzini wrote: > > > > > > On 30/11/2015 11:51, Greg Kurz wrote: > > > Since commit 8561c9244ddf1122d "exec: allocate PROT_NONE pages on top of RAM", > > > it is no longer possible to back guest RAM with hugepages on ppc64 hosts: > > > > > > mmap(NULL, 285212672, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3fff57000000 > > > mmap(0x3fff57000000, 268435456, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 19, 0) = -1 EBUSY (Device or resource busy) > > > > > > This is due to a limitation on ppc64 that requires MAP_FIXED mappings to have > > > the same page size as other mappings already present in the same "slice" of > > > virtual address space (Cc'ing Ben for details). This is exactly what happens > > > when calling mmap() above: first one uses native host page size (64k) and > > > second one uses huge page size (16M). > > > > > > To be sure we always have the same page size, let's use the same backend for > > > both calls to mmap(): this is enough to fix the ppc64 issue. > > > > > > This has no effect on RAM based mappings. > > > > > > Signed-off-by: Greg Kurz > > > --- > > > > > > This is a bug fix for 2.5 > > > > > > util/mmap-alloc.c | 3 ++- > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c > > > index c37acbe58ede..0ff221dd94f4 100644 > > > --- a/util/mmap-alloc.c > > > +++ b/util/mmap-alloc.c > > > @@ -21,7 +21,8 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared) > > > * space, even if size is already aligned. > > > */ > > > size_t total = size + align; > > > - void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); > > > + void *ptr = mmap(0, total, PROT_NONE, > > > + (fd == -1 ? MAP_ANONYMOUS : 0) | MAP_PRIVATE, fd, 0); > > > size_t offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr; > > > void *ptr1; > > > > > > > > > > Acked-by: Paolo Bonzini > > But why does this patch have any effect? > I'm worried that extra memory is still allocated > with this, even if it's not accessible. > And you are right because that is exactly what is happening with hugetlbfs_file_mmap()->hugetlb_reserve_pages() :-\ > If yes, we are better off disabling the protection for ppc. > Yes, this is the only alternative... I'll send a patch ASAP. Thanks ! -- Greg