From patchwork Fri Apr 4 12:56:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 27815 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D2AB520369 for ; Fri, 4 Apr 2014 12:58:53 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id fp1sf11117584pdb.5 for ; Fri, 04 Apr 2014 05:58:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=AExAk1gIAAa2s3W4ruBfB/DoAjQJtsmofBGahLL8oBQ=; b=YSHB+5mzPfaxfNL7U7XNRiXSH49czyHgTPp9tuYvtTLa8cIGQnn9SWYYEa20iUxGnJ NYgCqbyKqvCZQoPWBE2Gty3nMCDmQxicvSBWDQKHGYlwf9N0D5zi4gSeyKQuixcXo1/b 4ygukVBYD/jiDF0ztVER2j2WLZncaG+VLSmyq+jaYLCsh9Y/AWhU+t4KuUt9ZG7BSM9M AdYq10iE0nyyeLWNaJxUQBNWbbi6MR+WjgERqQxdTBGhYNkGynRGePNu72AxWZaLMQL9 PCLRQBM7gsgpj3AD4XWD0AHeapZjBxC/8TCeR5bMi2l6wJq7N3gANrVJBzoEBuEiPk94 qy3Q== X-Gm-Message-State: ALoCoQl2W+AaM3lVBRQRK+XRPCrPVD19IFzqOGSuR1TKblGkgxtOTSfVDS2vIGUoAOAdcZBBTWO9 X-Received: by 10.66.66.163 with SMTP id g3mr4749460pat.3.1396616333101; Fri, 04 Apr 2014 05:58:53 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.26.119 with SMTP id 110ls1015789qgu.20.gmail; Fri, 04 Apr 2014 05:58:53 -0700 (PDT) X-Received: by 10.58.111.163 with SMTP id ij3mr564206veb.26.1396616332974; Fri, 04 Apr 2014 05:58:52 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id sc7si1756933vdc.157.2014.04.04.05.58.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Apr 2014 05:58:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id il7so3128323vcb.32 for ; Fri, 04 Apr 2014 05:58:52 -0700 (PDT) X-Received: by 10.52.253.75 with SMTP id zy11mr11215924vdc.10.1396616332883; Fri, 04 Apr 2014 05:58:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp111907vcv; Fri, 4 Apr 2014 05:58:52 -0700 (PDT) X-Received: by 10.140.17.81 with SMTP id 75mr13592757qgc.35.1396616332069; Fri, 04 Apr 2014 05:58:52 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id jl9si3447005qcb.54.2014.04.04.05.58.51 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 04 Apr 2014 05:58:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WW3gE-0000O3-Gp; Fri, 04 Apr 2014 12:57:10 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WW3gD-0000Ml-3S for xen-devel@lists.xen.org; Fri, 04 Apr 2014 12:57:09 +0000 Received: from [85.158.137.68:31740] by server-14.bemta-3.messagelabs.com id C9/AA-30903-42CAE335; Fri, 04 Apr 2014 12:57:08 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1396616224!5082833!3 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.11.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10629 invoked from network); 4 Apr 2014 12:57:07 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 4 Apr 2014 12:57:07 -0000 X-IronPort-AV: E=Sophos;i="4.97,795,1389744000"; d="scan'208";a="116786620" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 04 Apr 2014 12:57:01 +0000 Received: from norwich.cam.xci-test.com (10.80.248.129) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.2.342.4; Fri, 4 Apr 2014 08:57:00 -0400 Received: from drall.uk.xensource.com ([10.80.16.71] helo=drall.uk.xensource.com.) by norwich.cam.xci-test.com with esmtp (Exim 4.72) (envelope-from ) id 1WW3g4-0000qs-AK; Fri, 04 Apr 2014 12:57:00 +0000 From: Ian Campbell To: Date: Fri, 4 Apr 2014 13:56:58 +0100 Message-ID: <1396616219-32219-2-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396616194.4211.223.camel@kazak.uk.xensource.com> References: <1396616194.4211.223.camel@kazak.uk.xensource.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: julien.grall@linaro.org, tim@xen.org, Ian Campbell , stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH 2/3] xen: arm: probe the kernel to determine the guest type earlier X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: We need to know if the kernel is 32- or 64- bit capable sooner so that we know what sort of domain we are building when allocating memory to it (so we can place appropriate limits when allocating RAM to the guest). At the moment kernel_prepare() decides this but it needs the memory to have already been allocated. Therefore split the probing functionality of kernel_prepare() and call it much earlier. The remainder of kernel_prepare() deals with where to place the kernel in RAM which can be deferred until kernel_load() so do so. Document the input and output of kernel_probe() and _load(). Signed-off-by: Ian Campbell Acked-by: Julien Grall --- xen/arch/arm/domain_build.c | 10 ++--- xen/arch/arm/kernel.c | 95 ++++++++++++++++++++++++------------------- xen/arch/arm/kernel.h | 26 +++++++++++- 3 files changed, 83 insertions(+), 48 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 502db84..4d6b26b 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1002,9 +1002,7 @@ int construct_dom0(struct domain *d) kinfo.unassigned_mem = dom0_mem; - allocate_memory(d, &kinfo); - - rc = kernel_prepare(&kinfo); + rc = kernel_probe(&kinfo); if ( rc < 0 ) return rc; @@ -1012,6 +1010,8 @@ int construct_dom0(struct domain *d) d->arch.type = kinfo.type; #endif + allocate_memory(d, &kinfo); + rc = prepare_dtb(d, &kinfo); if ( rc < 0 ) return rc; @@ -1024,8 +1024,8 @@ int construct_dom0(struct domain *d) p2m_restore_state(v); /* - * kernel_load will determine the placement of the initrd & fdt in - * RAM, so call it first. + * kernel_load will determine the placement of the kernel as well + * as the initrd & fdt in RAM, so call it first. */ kernel_load(&kinfo); /* initrd_load will fix up the fdt, so call it before dtb_load */ diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index d1fd307..a7a3e0c 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -116,13 +116,47 @@ static void place_modules(struct kernel_info *info, info->initrd_paddr = info->dtb_paddr + dtb_len; } +static paddr_t kernel_zimage_place(struct kernel_info *info) +{ + paddr_t load_addr; + +#ifdef CONFIG_ARM_64 + if ( info->type == DOMAIN_64BIT ) + return info->mem.bank[0].start + info->zimage.text_offset; +#endif + + /* + * If start is zero, the zImage is position independent, in this + * case Documentation/arm/Booting recommends loading below 128MiB + * and above 32MiB. Load it as high as possible within these + * constraints, while also avoiding the DTB. + */ + if (info->zimage.start == 0) + { + paddr_t load_end; + + load_end = info->mem.bank[0].start + info->mem.bank[0].size; + load_end = MIN(info->mem.bank[0].start + MB(128), load_end); + + load_addr = load_end - info->zimage.len; + /* Align to 2MB */ + load_addr &= ~((2 << 20) - 1); + } + else + load_addr = info->zimage.start; + + return load_addr; +} + static void kernel_zimage_load(struct kernel_info *info) { - paddr_t load_addr = info->zimage.load_addr; + paddr_t load_addr = kernel_zimage_place(info); paddr_t paddr = info->zimage.kernel_addr; paddr_t len = info->zimage.len; unsigned long offs; + info->entry = load_addr; + place_modules(info, load_addr, load_addr + len); printk("Loading zImage from %"PRIpaddr" to %"PRIpaddr"-%"PRIpaddr"\n", @@ -154,10 +188,10 @@ static void kernel_zimage_load(struct kernel_info *info) #ifdef CONFIG_ARM_64 /* - * Check if the image is a 64-bit zImage and setup kernel_info + * Check if the image is a 64-bit Image. */ -static int kernel_try_zimage64_prepare(struct kernel_info *info, - paddr_t addr, paddr_t size) +static int kernel_zimage64_probe(struct kernel_info *info, + paddr_t addr, paddr_t size) { /* linux/Documentation/arm64/booting.txt */ struct { @@ -196,12 +230,9 @@ static int kernel_try_zimage64_prepare(struct kernel_info *info, return -EINVAL; info->zimage.kernel_addr = addr; - - info->zimage.load_addr = info->mem.bank[0].start - + zimage.text_offset; info->zimage.len = end - start; + info->zimage.text_offset = zimage.text_offset; - info->entry = info->zimage.load_addr; info->load = kernel_zimage_load; info->type = DOMAIN_64BIT; @@ -213,8 +244,8 @@ static int kernel_try_zimage64_prepare(struct kernel_info *info, /* * Check if the image is a 32-bit zImage and setup kernel_info */ -static int kernel_try_zimage32_prepare(struct kernel_info *info, - paddr_t addr, paddr_t size) +static int kernel_zimage32_probe(struct kernel_info *info, + paddr_t addr, paddr_t size) { uint32_t zimage[ZIMAGE32_HEADER_LEN/4]; uint32_t start, end; @@ -250,28 +281,9 @@ static int kernel_try_zimage32_prepare(struct kernel_info *info, info->zimage.kernel_addr = addr; - /* - * If start is zero, the zImage is position independent, in this - * case Documentation/arm/Booting recommends loading below 128MiB - * and above 32MiB. Load it as high as possible within these - * constraints, while also avoiding the DTB. - */ - if (start == 0) - { - paddr_t load_end; - - load_end = info->mem.bank[0].start + info->mem.bank[0].size; - load_end = MIN(info->mem.bank[0].start + MB(128), load_end); - - info->zimage.load_addr = load_end - end; - /* Align to 2MB */ - info->zimage.load_addr &= ~((2 << 20) - 1); - } - else - info->zimage.load_addr = start; + info->zimage.start = start; info->zimage.len = end - start; - info->entry = info->zimage.load_addr; info->load = kernel_zimage_load; #ifdef CONFIG_ARM_64 @@ -283,6 +295,12 @@ static int kernel_try_zimage32_prepare(struct kernel_info *info, static void kernel_elf_load(struct kernel_info *info) { + /* + * TODO: can the ELF header be used to find the physical address + * to load the image to? Instead of assuming virt == phys. + */ + info->entry = info->elf.parms.virt_entry; + place_modules(info, info->elf.parms.virt_kstart, info->elf.parms.virt_kend); @@ -298,8 +316,8 @@ static void kernel_elf_load(struct kernel_info *info) free_xenheap_pages(info->elf.kernel_img, info->elf.kernel_order); } -static int kernel_try_elf_prepare(struct kernel_info *info, - paddr_t addr, paddr_t size) +static int kernel_elf_probe(struct kernel_info *info, + paddr_t addr, paddr_t size) { int rc; @@ -334,11 +352,6 @@ static int kernel_try_elf_prepare(struct kernel_info *info, } #endif - /* - * TODO: can the ELF header be used to find the physical address - * to load the image to? Instead of assuming virt == phys. - */ - info->entry = info->elf.parms.virt_entry; info->load = kernel_elf_load; if ( elf_check_broken(&info->elf.elf) ) @@ -355,7 +368,7 @@ err: return rc; } -int kernel_prepare(struct kernel_info *info) +int kernel_probe(struct kernel_info *info) { int rc; @@ -373,12 +386,12 @@ int kernel_prepare(struct kernel_info *info) printk("Loading kernel from boot module %d\n", MOD_KERNEL); #ifdef CONFIG_ARM_64 - rc = kernel_try_zimage64_prepare(info, start, size); + rc = kernel_zimage64_probe(info, start, size); if (rc < 0) #endif - rc = kernel_try_zimage32_prepare(info, start, size); + rc = kernel_zimage32_probe(info, start, size); if (rc < 0) - rc = kernel_try_elf_prepare(info, start, size); + rc = kernel_elf_probe(info, start, size); return rc; } diff --git a/xen/arch/arm/kernel.h b/xen/arch/arm/kernel.h index 2c27c64..2f3d2d4 100644 --- a/xen/arch/arm/kernel.h +++ b/xen/arch/arm/kernel.h @@ -31,8 +31,11 @@ struct kernel_info { union { struct { paddr_t kernel_addr; - paddr_t load_addr; paddr_t len; +#ifdef CONFIG_ARM_64 + paddr_t text_offset; /* 64-bit Image only */ +#endif + paddr_t start; /* 32-bit zImage only */ } zimage; struct { @@ -44,7 +47,26 @@ struct kernel_info { }; }; -int kernel_prepare(struct kernel_info *info); +/* + * Probe the kernel to detemine its type and select a loader. + * + * Sets in info: + * ->type + * ->load hook, and sets loader specific variables ->{zimage,elf} + */ +int kernel_probe(struct kernel_info *info); +/* + * Loads the kernel into guest RAM. + * + * Expects to be set in info when called: + * ->mem + * ->fdt + * + * Sets in info: + * ->entry + * ->dtb_paddr + * ->initrd_paddr + */ void kernel_load(struct kernel_info *info); #endif /* #ifdef __ARCH_ARM_KERNEL_H__ */