From patchwork Fri Jan 23 21:21:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john cooper X-Patchwork-Id: 3830 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n0NLUNK3021847 for ; Fri, 23 Jan 2009 21:30:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755454AbZAWVaV (ORCPT ); Fri, 23 Jan 2009 16:30:21 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755514AbZAWVaV (ORCPT ); Fri, 23 Jan 2009 16:30:21 -0500 Received: from mx2.redhat.com ([66.187.237.31]:52220 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755454AbZAWVaT (ORCPT ); Fri, 23 Jan 2009 16:30:19 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n0NLU1b6012002; Fri, 23 Jan 2009 16:30:02 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n0NLU1IQ003030; Fri, 23 Jan 2009 16:30:01 -0500 Received: from anvil.naka.net (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n0NLTrMC019541; Fri, 23 Jan 2009 16:29:55 -0500 Message-ID: <497A34EA.3050703@redhat.com> Date: Fri, 23 Jan 2009 16:21:46 -0500 From: john cooper User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: Avi Kivity CC: john cooper , kvm@vger.kernel.org, aliguori@us.ibm.com, Marcelo Tosatti , john.cooper@redhat.com Subject: Re: Resend: patch: qemu + hugetlbfs.. References: <4873E400.4000409@third-harmonic.com> <4873F395.6030209@codemonkey.ws> <4874051A.8000802@third-harmonic.com> <48740F86.3050306@codemonkey.ws> <20080709170301.GA11439@dmt.cnet> <4874F156.2010708@codemonkey.ws> <48763B86.6060402@third-harmonic.com> <48764DAF.6060502@codemonkey.ws> <48766E03.4090901@third-harmonic.com> <48767558.50301@codemonkey.ws> <48767B20.20806@third-harmonic.com> <4876815E.3010109@codemonkey.ws> <48B33AAD.8000508@third-harmonic.com> <496FEECB.2060208@third-harmonic.com> <4975A78B.1060101@redhat.com> In-Reply-To: <4975A78B.1060101@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Avi Kivity wrote: > john cooper wrote: >> This trivial patch never did manage to find its way >> in. Marcelo called it to my attention earlier in >> the week. I've tweaked it to apply to kvm-83 and >> the resulting patch is attached. I've left the >> prior e-mail discussion below for reference. >> > > Sorry for missing this (copying me helps). Please resubmit with a > signoff.Also, please protect with #ifdef MAP_POPULATE to ease merging > into upstream eventually. Updated patch attached. -john Signed-off-by: john cooper ================================================================= --- a/qemu/vl.c +++ b/qemu/vl.c @@ -237,6 +237,9 @@ int semihosting_enabled = 0; int time_drift_fix = 0; unsigned int kvm_shadow_memory = 0; const char *mem_path = NULL; +#ifdef MAP_POPULATE +int mem_prealloc = 1; /* force preallocation of physical target memory */ +#endif int hpagesize = 0; const char *cpu_vendor_string; #ifdef TARGET_ARM @@ -4116,7 +4119,12 @@ static void help(int exitcode) #endif "-tdf inject timer interrupts that got lost\n" "-kvm-shadow-memory megs set the amount of shadow pages to be allocated\n" - "-mem-path set the path to hugetlbfs/tmpfs mounted directory, also enables allocation of guest memory with huge pages\n" + "-mem-path set the path to hugetlbfs/tmpfs mounted directory, also\n" + " enables allocation of guest memory with huge pages\n" +#ifdef MAP_POPULATE + "-mem-prealloc toggles preallocation of -mem-path backed physical memory\n" + " at startup. Default is enabled.\n" +#endif "-option-rom rom load a file, rom, into the option ROM space\n" #ifdef TARGET_SPARC "-prom-env variable=value set OpenBIOS nvram variables\n" @@ -4246,6 +4254,9 @@ enum { QEMU_OPTION_tdf, QEMU_OPTION_kvm_shadow_memory, QEMU_OPTION_mempath, +#ifdef MAP_POPULATE + QEMU_OPTION_mem_prealloc, +#endif }; typedef struct QEMUOption { @@ -4381,6 +4392,9 @@ static const QEMUOption qemu_options[] = { "icount", HAS_ARG, QEMU_OPTION_icount }, { "incoming", HAS_ARG, QEMU_OPTION_incoming }, { "mem-path", HAS_ARG, QEMU_OPTION_mempath }, +#ifdef MAP_POPULATE + { "mem-prealloc", 0, QEMU_OPTION_mem_prealloc }, +#endif { NULL }, }; @@ -4663,6 +4677,9 @@ void *alloc_mem_area(size_t memory, unsi char *filename; void *area; int fd; +#ifdef MAP_POPULATE + int flags; +#endif if (asprintf(&filename, "%s/kvm.XXXXXX", path) == -1) return NULL; @@ -4690,13 +4707,21 @@ void *alloc_mem_area(size_t memory, unsi */ ftruncate(fd, memory); +#ifdef MAP_POPULATE + /* NB: MAP_POPULATE won't exhaustively alloc all phys pages in the case + * MAP_PRIVATE is requested. For mem_prealloc we mmap as MAP_SHARED + * to sidestep this quirk. + */ + flags = mem_prealloc ? MAP_POPULATE|MAP_SHARED : MAP_PRIVATE; + area = mmap(0, memory, PROT_READ|PROT_WRITE, flags, fd, 0); +#else area = mmap(0, memory, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); +#endif if (area == MAP_FAILED) { - perror("mmap"); + perror("alloc_mem_area: can't mmap hugetlbfs pages"); close(fd); - return NULL; + return (NULL); } - *len = memory; return area; } @@ -5377,6 +5402,11 @@ int main(int argc, char **argv, char **e case QEMU_OPTION_mempath: mem_path = optarg; break; +#ifdef MAP_POPULATE + case QEMU_OPTION_mem_prealloc: + mem_prealloc = !mem_prealloc; + break; +#endif case QEMU_OPTION_name: qemu_name = optarg; break; ================================================================= --- a/kernel/x86/Kbuild +++ b/kernel/x86/Kbuild @@ -9,8 +9,8 @@ kvm-objs := kvm_main.o x86.o mmu.o x86_e ifeq ($(EXT_CONFIG_KVM_TRACE),y) kvm-objs += kvm_trace.o endif -ifeq ($(CONFIG_DMAR),y) -kvm-objs += vtd.o +ifeq ($(CONFIG_IOMMU_API),y) +kvm-objs += iommu.o endif kvm-intel-objs := vmx.o vmx-debug.o ../external-module-compat.o kvm-amd-objs := svm.o ../external-module-compat.o