From patchwork Mon Jun 27 07:53:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Behme X-Patchwork-Id: 9200001 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 1367C6075F for ; Mon, 27 Jun 2016 07:56:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0352928159 for ; Mon, 27 Jun 2016 07:56:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA8A728488; Mon, 27 Jun 2016 07:56:49 +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_SIGNED, 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 2CDB028159 for ; Mon, 27 Jun 2016 07:56:47 +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 1bHRN0-00087c-EO; Mon, 27 Jun 2016 07:54:14 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bHRMy-00087W-2l for xen-devel@lists.xenproject.org; Mon, 27 Jun 2016 07:54:12 +0000 Received: from [85.158.139.211] by server-10.bemta-5.messagelabs.com id 6C/96-12215-3ABD0775; Mon, 27 Jun 2016 07:54:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsXSzf+WW3fR7YJ wgwfLjS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyTs1UKepQqrhx+ztbAOFuqi5GLQ0jgLKPE g4X7WUAcFoG3TBIfu2awQmSeM0pMezmbGcJZwyjReHI7UxcjJ5CzklHi/cd4EJtNQEti54QOd hBbRKBcYtW+R0DdHBzMAhoSG7aBhYUFzCW2XJoLZrMIqEpsmNjEBmLzCrhLXH+/FCwuISAnsW 7yd3aIuKDEyZlPWEBsZgEJiYMvXjBD1IhITPz7ng1kvISApcTJYwkgp0kIrGOR2PR9KdsERsF ZSNpnIWlfwMi0ilGjOLWoLLVI19hAL6koMz2jJDcxM0fX0MBULze1uDgxPTUnMalYLzk/dxMj MEDrGRgYdzBOWOV3iFGSg0lJlHfbo9xwIb6k/JTKjMTijPii0pzU4kOMMhwcShK8j28VhAsJF qWmp1akZeYAYwUmLcHBoyTCewkkzVtckJhbnJkOkTrFqCglzrsGJCEAksgozYNrg8XnJUZZKW FeRgYGBiGegtSi3MwSVPlXjOIcjErCvPtBpvBk5pXATX8FtJgJaDFrdT7I4pJEhJRUAyPjpSr FW+eDptbuvqgpVlD1L+mZxJ/flRGaa+O23GWdvmHC/Tu5ibMXFE5bUbHXw3jLW/ar2k7J3cI3 MroV3klF75IQCdm3q//3wTCty5nvuvnqFZLn+ubME9/JqOQ9/ZDafttooTd/LA2vW/8Nbw9eM ZWp5e+5Z7KLnOy2nj86/3FY4J/t+3YosRRnJBpqMRcVJwIAxGCaZsoCAAA= X-Env-Sender: Dirk.Behme@de.bosch.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1467014050!47122215!1 X-Originating-IP: [139.15.237.11] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM5LjE1LjIzNy4xMSA9PiAxNTMwMzA=\n X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 11837 invoked from network); 27 Jun 2016 07:54:10 -0000 Received: from smtp6-v.fe.bosch.de (HELO smtp6-v.fe.bosch.de) (139.15.237.11) by server-9.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 27 Jun 2016 07:54:10 -0000 Received: from vsmta13.fe.internet.bosch.com (unknown [10.4.98.53]) by imta23.fe.bosch.de (Postfix) with ESMTP id 772071580235 for ; Mon, 27 Jun 2016 09:54:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1467014050; bh=Fkztw+w29n/RtCYHbEXsFbnY3M0zIvbb7k+ZGSlsatU=; l=10; h=From:From:Reply-To:Sender; b=dQqWeRbUAJkbuzIFe1CuMIfnMXkrXmAgevkmJBJfBVjmZbpv4c9n3LbLLziv9op4a 0ZqJgP5nhOeBZwTGRiY2jF6CF4sBuJShSh7yBetGEC+bvvqiEXq5jybpLGNhvK3E7c YJYoc7Zt0NWX7y9bR43ehP8i1itgbVZIjjfRutjQ= Received: from FE-HUB1000.de.bosch.com (vsgw22.fe.internet.bosch.com [10.4.98.11]) by vsmta13.fe.internet.bosch.com (Postfix) with ESMTP id 1D8082E40876 for ; Mon, 27 Jun 2016 09:54:10 +0200 (CEST) Received: from hi-z08if.hi.de.bosch.com (10.34.209.31) by FE-HUB1000.de.bosch.com (10.4.103.107) with Microsoft SMTP Server id 14.3.195.1; Mon, 27 Jun 2016 09:54:08 +0200 Received: from hi-z08if.hi.de.bosch.com (localhost [127.0.0.1]) by hi-z08if.hi.de.bosch.com (Postfix) with ESMTP id 4F74D625F21; Mon, 27 Jun 2016 09:53:13 +0200 (CEST) From: Dirk Behme To: , Julien Grall , Stefano Stabellini Date: Mon, 27 Jun 2016 09:53:10 +0200 Message-ID: <1467013990-12796-1-git-send-email-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.8.0 MIME-Version: 1.0 X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-22414.006 X-TMASE-MatchedRID: aZbaxZq7w48ryFHbNnBLG7U+IyHhkXf1FuNF4lJG6xsL/50zj0KL7BHx rRblSw8b9Pkiah4SuH4MfgmZ55C/YfF4Lj+zpFjfVnhTcytb5dIwl5uLW9ec01pbYq2f4jz+sCL 2uKJULhPKwJG6rXlLlAMCC5iRZIS0pljg/F9ExYTaGKmW8Fvr+wrefVId6fzVXCmcAC8DBrNvt4 SwM/2FHSACA5ub2Vruc4cQwtoVK6k79MzjMhg/8THzsy28T+GVRtu4vtjjtzRm+6Fpy57LxaeXc NCCFqyku7ZVT49TiF9D9JDZyhGdD3sQZsIG1c2HA9lly13c/gHt/okBLaEo+LEz/84sct8s8z70 XDTUjsY89k1/qnrX1k5Pq6Rc+D9505iwHvhHt5yMVQb49Y23I+HZW6PYTK5Kyaz/THj7NZyjxYy RBa/qJbZ20YSJGhw7fJ5/bZ6npdg7AFczfjr/7CFN4RpXK+pTQbHME8NyCYkwRgvC/bzZV9NAHX G6FGsrs/QBWKZof+Q= Cc: Dirk Behme Subject: [Xen-devel] [PATCH v4] xen: arm: Update arm64 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP With the Linux kernel commits https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/Documentation/arm64/booting.txt?id=4370eec05a887b0cd4392cd5dc5b2713174745c0 https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/Documentation/arm64/booting.txt?id=a2c1d73b94ed49f5fac12e95052d7b140783f800 the arm64 image header changed. While the size of the header isn't changed, some members have changed their usage. Update Xen to this updated image header. The main changes are that the first magic is gone and that there is an image size, now. In case we read a size != 0, let's use this image size, now. This does allow us to check if the kernel Image is larger than the size given in the device tree, too. Additionally, add an error message if the magic is not found. This might be the case with kernel's < 3.12 prior to https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4370eec05a887b0cd4392cd5dc5b2713174745c0 which introduced the second magic. This is acceptable as the support of Xen for ARM64 in Linux has been added in Linux 3.11 and the number of boards supported by Linux 3.11 on ARM64 is very limited: ARM models and X-gene. And for the latter it was an early support with only the serial and timer upstreamed. Signed-off-by: Dirk Behme Reviewed-by: Julien Grall --- Changes in v4: Print header error only based on ZIMAGE64_MAGIC_V0. Drop comment and unnecessary if statement. Changes in v3: Just update of the commit message regarding the support for kernels < 3.12. No change to the patch itself. xen/arch/arm/kernel.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 9871bd9..1797097 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -29,7 +29,7 @@ #define ZIMAGE32_MAGIC 0x016f2818 #define ZIMAGE64_MAGIC_V0 0x14000008 -#define ZIMAGE64_MAGIC_V1 0x644d5241 /* "ARM\x64" */ +#define ZIMAGE64_MAGIC 0x644d5241 /* "ARM\x64" */ struct minimal_dtb_header { uint32_t magic; @@ -335,17 +335,19 @@ static int kernel_zimage64_probe(struct kernel_info *info, { /* linux/Documentation/arm64/booting.txt */ struct { - uint32_t magic0; - uint32_t res0; - uint64_t text_offset; /* Image load offset */ - uint64_t res1; + union { + uint32_t code0; + uint32_t magic0; /* Old header magic */ + }; + uint32_t code1; + uint64_t text_offset; /* Image load offset, little endian */ + uint64_t image_size; /* Effective Image size, little endian */ + uint64_t flags; uint64_t res2; - /* zImage V1 only from here */ uint64_t res3; uint64_t res4; - uint64_t res5; - uint32_t magic1; - uint32_t res6; + uint32_t magic; /* Magic number, little endian, "ARM\x64" */ + uint32_t res5; } zimage; uint64_t start, end; @@ -354,20 +356,29 @@ static int kernel_zimage64_probe(struct kernel_info *info, copy_from_paddr(&zimage, addr, sizeof(zimage)); - if ( zimage.magic0 != ZIMAGE64_MAGIC_V0 && - zimage.magic1 != ZIMAGE64_MAGIC_V1 ) + if ( zimage.magic != ZIMAGE64_MAGIC ) { + if ( zimage.magic0 == ZIMAGE64_MAGIC_V0 ) + printk(XENLOG_ERR "No valid magic found in header! Kernel too old\n"); return -EINVAL; + } - /* Currently there is no length in the header, so just use the size */ start = 0; - end = size; /* - * Given the above this check is a bit pointless, but leave it - * here in case someone adds a length field in the future. + * Where image_size is non-zero image_size is little-endian + * and must be respected. */ - if ( (end - start) > size ) + if ( zimage.image_size ) + end = zimage.image_size; + else + end = size; + + if ( (end - start) > size ) { + printk(XENLOG_ERR "Error: Kernel Image size: %lu bytes > bootmodule size: %lu bytes\n", + zimage.image_size, (uint64_t)size); + printk(XENLOG_ERR "The field 'size' does not match the size of blob!\n"); return -EINVAL; + } info->zimage.kernel_addr = addr; info->zimage.len = end - start;