From patchwork Thu Sep 1 01:38:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 9308193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 96A9E601C0 for ; Thu, 1 Sep 2016 01:41:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BF84290A8 for ; Thu, 1 Sep 2016 01:41:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F0B0290B6; Thu, 1 Sep 2016 01:41:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7EE20290A8 for ; Thu, 1 Sep 2016 01:41:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bfGxm-0006wY-VL; Thu, 01 Sep 2016 01:38:42 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bfGxl-0006wQ-F3 for xen-devel@lists.xen.org; Thu, 01 Sep 2016 01:38:41 +0000 Received: from [193.109.254.147] by server-4.bemta-6.messagelabs.com id B1/53-29421-0A687C75; Thu, 01 Sep 2016 01:38:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrAIsWRWlGSWpSXmKPExsVyMfSOi+7ctuP hBgenyFks+biYxYHR4+ju30wBjFGsmXlJ+RUJrBmz/65kLmiwqPgy6TBjA+NC3S5GLg4hgQmM ErMa1rOBOCwCl1gkmhbsAnMkBN6xSOzasZSxi5ETyImRmH3lMJRdKfHn4XZmEFtIQEVi7qYeR ohR05kk2o+eBkuwCahJHHk/EyjBAdRgLPH8Zg5IWETAUGLyqr+sIDazgKXE+Q0f2UFsYQFrib UzGphAbBYBVYlXB9aA1fAK2Ev82PAIaq+cxPWZ05kmMPIvYGRYxahRnFpUllqka2Sql1SUmZ5 RkpuYmaNraGCml5taXJyYnpqTmFSsl5yfu4kRGEIMQLCDcdWCwEOMkhxMSqK8anHHw4X4kvJT KjMSizPii0pzUosPMcpwcChJ8L5vAcoJFqWmp1akZeYAgxkmLcHBoyTCG9QKlOYtLkjMLc5Mh 0idYrTk2PL72lomjmNzbwDJbVPvrWUSYsnLz0uVEuf9CTJPAKQhozQPbhws4i4xykoJ8zICHS jEU5BalJtZgir/ilGcg1FJmPcxyBSezLwSuK2vgA5iAjqo4M5hkINKEhFSUg2M4Y5MuU37jnA cb166drrm3mNXHf8WxYUFVqvuuWa3T4U/99oUp3D284uuBL45Uvnq5q/3rBMtW+50BPMbmf5b MjX22tHm6aJylvKGf1m/7pqg4RXtbzdX/shG/ymVJT9UAy9JP3gRnar8Oq3m0uSdn39Nm1l54 9X5dgOOmXv6W6JUGPJTvr5dq8RSnJFoqMVcVJwIAIQhaQ6zAgAA X-Env-Sender: van.freenix@gmail.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1472693916!52233865!1 X-Originating-IP: [209.85.220.68] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23079 invoked from network); 1 Sep 2016 01:38:37 -0000 Received: from mail-pa0-f68.google.com (HELO mail-pa0-f68.google.com) (209.85.220.68) by server-7.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 1 Sep 2016 01:38:37 -0000 Received: by mail-pa0-f68.google.com with SMTP id cf3so3417779pad.2 for ; Wed, 31 Aug 2016 18:38:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=USp5+8bD9dd9CoZfClRwjEPIPdNPZQsK77PqceXPmtY=; b=Tb4qyORSO1Ek3Lt0G/mWfyrFvNKVQiMiFsRvrUAn1fBQuOdSiQvoZXl28Xfhi3TT0p ouGtMFdz46B603JXL8SFr5gHZGL3QNCcyRK8VQjjdwDOIYTmNnF9u2+18s9hyBf+LYcg 2Co+iiyK5NLn/IOdutNHuvun0056l6bUPBbfRKuCZsFNRwq04DuIpvsso7DPU7QiVWLx 3E/kp3uktylRj685YxTS1JPojN+gq+BR/+2MDLCT1n5E0YeVlEct2RfnFDZvahKXo3MS oATAY2S4UASQgBhPJxV8g60KAh+cXyi8QskHM3HM+4mp8Caf3TLMsxSxYqjsOhDwYrrv dS9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=USp5+8bD9dd9CoZfClRwjEPIPdNPZQsK77PqceXPmtY=; b=COcaymnbcX6S+zEgr2pGlGHFL2oEiXPhMmkPqCyuyXX1UdbH5RK8YD4JQ6V213eD+O pq3rIGrWTrQ3mV3reL+A2+FpMT5uNWTfrbTfPCb6UBGNUFa+8pOt2hA1iJboZMO3UCDI /mR9Q9w6aGKDVNGUC9QWyfJXF5O7hKlAAUPNX1dTHhX/ebiu9/GUZ2tMXds/3+qWuYa6 2zgs0S7p3VdiSac6isf1Y99aIFSOSQoldcTb6aj0yfWEDCvaIbyBzjJkqKMAWeK1n/xm 36JbAf0KvM6mQ+UlYqZA+wCb5Guq0rSR+pznBmdQY6PoiI/FtLrZTgY2IqYfDwYgKfCy 0zoA== X-Gm-Message-State: AE9vXwMaOkMMIrXPU6dILNnKjUAoE67jZsgiTZJ5pcOo2zkMgArkXeOgYAmcJk/EmMeMpg== X-Received: by 10.66.169.68 with SMTP id ac4mr22499295pac.85.1472693915514; Wed, 31 Aug 2016 18:38:35 -0700 (PDT) Received: from linux-u7w5.ap.freescale.net (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.gmail.com with ESMTPSA id c125sm2503717pfc.40.2016.08.31.18.38.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Aug 2016 18:38:34 -0700 (PDT) From: Peng Fan X-Google-Original-From: Peng Fan To: sstabellini@kernel.org, julien.grall@arm.com Date: Thu, 1 Sep 2016 09:38:21 +0800 Message-Id: <1472693901-2459-1-git-send-email-peng.fan@nxp.com> X-Mailer: git-send-email 2.6.6 Cc: Peng Fan , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH V2] xen/arm: arm64: Update the Image header X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch is mainly modified from Linux kernel: [1] commit a2c1d73b94ed: arm64: Update the Image header [2] commit 6ad1fe5d9077: arm64: avoid R_AARCH64_ABS64 relocations for Image header fields From [1]: " This patch adds an effective image size to the kernel header which describes the amount of memory from the start of the kernel Image binary which the kernel expects to use before detecting memory and handling any memory reservations. This can be used by bootloaders to choose suitable locations to load the kernel and/or other binaries such that the kernel will not clobber any memory unexpectedly. As before, memory reservations are required to prevent the kernel from clobbering these locations later. Both the image load offset and the effective image size are forced to be little-endian regardless of the native endianness of the kernel to enable bootloaders to load a kernel of arbitrary endianness. Bootloaders which wish to make use of the load offset can inspect the effective image size field for a non-zero value to determine if the offset is of a known endianness. To enable software to determine the endinanness of the kernel as may be required for certain use-cases, a new flags field (also little-endian) is added to the kernel header to export this information. " In this patch, XEN_VIRT_START is used as the text offset. Then, bootloader, such as U-Boot, will load the xen image to "dram_base + text_offset". Not choose 0 as the text offset, because we may have spin table at dram_base. Loading xen to dram_base will override the spin table. Introduce image.h and macros.h in this patch, just as Linux kernel. Signed-off-by: Peng Fan Cc: Stefano Stabellini Cc: Julien Grall --- V2: Addressing Julien's comments to follow linux kernel patch: a2c1d73b94ed49 "arm64: Update the Image header" xen/arch/arm/arm64/head.S | 7 +++-- xen/arch/arm/xen.lds.S | 5 +++ xen/include/asm-arm/arm64/image.h | 62 ++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/arm64/macros.h | 15 +++++++++ xen/include/asm-arm/macros.h | 2 +- 5 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 xen/include/asm-arm/arm64/image.h create mode 100644 xen/include/asm-arm/arm64/macros.h diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 91e2817..0226463 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -21,6 +21,7 @@ */ #include +#include #include #include #include @@ -114,9 +115,9 @@ efi_head: */ add x13, x18, #0x16 b real_start /* branch to kernel start */ - .quad 0 /* Image load offset from start of RAM */ - .quad 0 /* reserved */ - .quad 0 /* reserved */ + le64sym _xen_offset_le /* Image load offset from start of RAM, little-endian */ + le64sym _xen_size_le /* Effective size of kernel image, little-endian */ + le64sym _xen_flags_le /* Informative flags, little-endian */ .quad 0 /* reserved */ .quad 0 /* reserved */ .quad 0 /* reserved */ diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index b24e93b..854c243 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -6,6 +6,7 @@ #include #include #include +#include #undef ENTRY #undef ALIGN @@ -196,6 +197,10 @@ SECTIONS .dtb : { *(.dtb) } :text #endif +#if defined(__aarch64__) + HEAD_SYMBOLS +#endif + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text) diff --git a/xen/include/asm-arm/arm64/image.h b/xen/include/asm-arm/arm64/image.h new file mode 100644 index 0000000..54751ca --- /dev/null +++ b/xen/include/asm-arm/arm64/image.h @@ -0,0 +1,62 @@ +/* + * Copied and modified from Linux + * "commit 29b4817d4018df78086157ea3a55c1d9424a7cfc" + * + * Linker script macros to generate Image header fields. + * + * Copyright (C) 2014 ARM Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef __ASM_IMAGE_H +#define __ASM_IMAGE_H + +#ifdef CONFIG_CPU_BIG_ENDIAN +#define DATA_LE32(data) \ + ((((data) & 0x000000ff) << 24) | \ + (((data) & 0x0000ff00) << 8) | \ + (((data) & 0x00ff0000) >> 8) | \ + (((data) & 0xff000000) >> 24)) +#else +#define DATA_LE32(data) ((data) & 0xffffffff) +#endif + +#define DEFINE_IMAGE_LE64(sym, data) \ + sym##_lo32 = DATA_LE32((data) & 0xffffffff); \ + sym##_hi32 = DATA_LE32((data) >> 32) + +#ifdef CONFIG_CPU_BIG_ENDIAN +#define __HEAD_FLAG_BE 1 +#else +#define __HEAD_FLAG_BE 0 +#endif + +#define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2) + +#define __HEAD_FLAG_PHYS_BASE 1 + +#define __HEAD_FLAGS ((__HEAD_FLAG_BE << 0) | \ + (__HEAD_FLAG_PAGE_SIZE << 1) | \ + (__HEAD_FLAG_PHYS_BASE << 3)) + +/* + * These will output as part of the Image header, which should be little-endian + * regardless of the endianness of the kernel. While constant values could be + * endian swapped in head.S, all are done here for consistency. + */ +#define HEAD_SYMBOLS \ + DEFINE_IMAGE_LE64(_xen_size_le, _end - _start); \ + DEFINE_IMAGE_LE64(_xen_offset_le, XEN_VIRT_START); \ + DEFINE_IMAGE_LE64(_xen_flags_le, __HEAD_FLAGS); + +#endif /* __ASM_IMAGE_H */ diff --git a/xen/include/asm-arm/arm64/macros.h b/xen/include/asm-arm/arm64/macros.h new file mode 100644 index 0000000..25e57af --- /dev/null +++ b/xen/include/asm-arm/arm64/macros.h @@ -0,0 +1,15 @@ +#ifndef __ASM_ARM_ARM64_MACROS_H +#define __ASM_ARM_ARM64_MACROS_H + +/* + * Emit a 64-bit absolute little endian symbol reference in a way that + * ensures that it will be resolved at build time, even when building a + * PIE binary. This requires cooperation from the linker script, which + * must emit the lo32/hi32 halves individually. + */ + .macro le64sym, sym + .long \sym\()_lo32 + .long \sym\()_hi32 + .endm + +#endif /* __ASM_ARM_ARM32_MACROS_H */ diff --git a/xen/include/asm-arm/macros.h b/xen/include/asm-arm/macros.h index 5d837cb..1d4bb41 100644 --- a/xen/include/asm-arm/macros.h +++ b/xen/include/asm-arm/macros.h @@ -8,7 +8,7 @@ #if defined (CONFIG_ARM_32) # include #elif defined(CONFIG_ARM_64) -/* No specific ARM64 macros for now */ +# include #else # error "unknown ARM variant" #endif