From: Paolo Bonzini Subject: Re: [kvm-unit-tests PATCH v2 6/6] lib/x86/vm: enable malloc and friends Date: Thu, 3 Nov 2016 20:19:44 +0100 Message-ID: <9fb7d690-13c3-53a4-76d0-6a3b19ba44b0@redhat.com> References: <1478119966-13252-1-git-send-email-drjones@redhat.com> <1478119966-13252-7-git-send-email-drjones@redhat.com> <20161103145856.weexgnucvpz3ul6q@kamzik.brq.redhat.com> <20161103165129.dtb265bwjqexdl7y@kamzik.brq.redhat.com> <21187a7d-2aff-e8ca-110f-4ec8607eeafc@redhat.com> <20161103181242.yrj4cs62bn6xop5m@kamzik.brq.redhat.com> <20161103184235.nsc3o5m3ai63aiyr@kamzik.brq.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, lvivier@redhat.com, thuth@redhat.com To: Andrew Jones Return-path: Received: from mx1.redhat.com ([209.132.183.28]:52442 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751539AbcKCTTt (ORCPT ); Thu, 3 Nov 2016 15:19:49 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 641CA31B321 for ; Thu, 3 Nov 2016 19:19:48 +0000 (UTC) In-Reply-To: <20161103184235.nsc3o5m3ai63aiyr@kamzik.brq.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 03/11/2016 19:42, Andrew Jones wrote: > On Thu, Nov 03, 2016 at 07:20:20PM +0100, Paolo Bonzini wrote: >> >> >> On 03/11/2016 19:12, Andrew Jones wrote: >>> On Thu, Nov 03, 2016 at 06:34:45PM +0100, Paolo Bonzini wrote: >>>> You're right, it needs alignment too. So yeah, early_memalign's code >>>> can be repurposed as the early allocator's morecore callback. For the >>>> current trivial malloc implementation, malloc would be implemented as >>>> ops->morecore(size, align_min). I think we agree on the overall idea >>>> and on having only one function pointer. >>> >>> Yup, already done. But 2, not 1, pointers. Still need 'free' too. >> >> Didn't we say that the morecore allocator would only grow? > > morecore[phys_alloc] only grows, free -> {} > morecore[vmemalign] can do both, free -> vfree Though there'd be no caller of .free, and vfree is sitting mostly unused right now. You decide. > Hmm, I see what's going on now in x86. First, setup_vm should be doing > setup_mmu *before* 'free_memory' (what I renamed to heap_init), because > it assumes it's using virtual address with page_alloc/free. Second, x86 > creates an identity map up to end_of_memory, and that's the last address > the heap knows about too. So, if we want to allocate free virtual > addresses upwards, then we should start from end_of_memory. Right, from 2G. There's even a comment. :) >>>> 5) moves the virt allocator and the vmalloc ops to a new file >>>> lib/vmalloc.c (with install_page() remaining as the sole hook into >>>> arch-specific code), removing what's now dead from lib/vmalloc.c. >>> >>> Yeah, this is a good next step. Will do. > > This one looks like we'll need to cleanup the install_page parameter > expectations a bit in order to keep arch-specific stuff out of the callers, > but that should be doable. The first argument can go---its always phys_to_virt(read_cr3())---and with that it should be fine. Paolo