From nobody Mon May 13 17:08:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1675327810; cv=pass; d=zohomail.com; s=zohoarc; b=UZ83Hq7dqiQOWhIUFz7dM9dx94lR93PIb+2jl7HdFZRTkSHW3vsMsZ1ehxCF99Fogr5mX7x6yy6AVz3/E/18GJdEddSzfHOazr0pDVlxz4U/nKs81tzSQn+iDTsariX77RZ1CrUj08DEPqKyhxuv5tEpaGcHaNrs0pi203VpdlY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675327810; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uBLNfq0kNGD8ONWUKgdnR9q15jFiaFT0XCVIzdVZEEQ=; b=C3NEjRsPwmSyO92ExF7j3wqNMyK7P6NHqTinIOsZzpNMecdDYC6CvT2JP7svUzl5JH6B1e207Dl/+rHj2x1ynRZ5EGP7wGYQZE0AjthYDzGt812Q6YXsJZCRsFNmVBrsGACMjEY0LPHNGA5gen5kxQCGXy9SLD/UjvIM9NV65kY= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1675327810563896.1988473639246; Thu, 2 Feb 2023 00:50:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.488596.756735 (Exim 4.92) (envelope-from ) id 1pNVHf-0004Qi-3h; Thu, 02 Feb 2023 08:49:31 +0000 Received: by outflank-mailman (output) from mailman id 488596.756735; Thu, 02 Feb 2023 08:49:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pNVHf-0004Qb-0B; Thu, 02 Feb 2023 08:49:31 +0000 Received: by outflank-mailman (input) for mailman id 488596; Thu, 02 Feb 2023 08:49:30 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pNVHe-0004Po-2O for xen-devel@lists.xenproject.org; Thu, 02 Feb 2023 08:49:30 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20613.outbound.protection.outlook.com [2a01:111:f400:fe5b::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7fa8a137-a2d6-11ed-b63b-5f92e7d2e73a; Thu, 02 Feb 2023 09:49:27 +0100 (CET) Received: from BN9P223CA0018.NAMP223.PROD.OUTLOOK.COM (2603:10b6:408:10b::23) by MN2PR12MB4566.namprd12.prod.outlook.com (2603:10b6:208:26a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38; Thu, 2 Feb 2023 08:49:23 +0000 Received: from BN8NAM11FT116.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10b:cafe::5f) by BN9P223CA0018.outlook.office365.com (2603:10b6:408:10b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.25 via Frontend Transport; Thu, 2 Feb 2023 08:49:23 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT116.mail.protection.outlook.com (10.13.176.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6064.27 via Frontend Transport; Thu, 2 Feb 2023 08:49:23 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 2 Feb 2023 02:49:23 -0600 Received: from XIR-MICHALO-L1.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 2 Feb 2023 02:49:21 -0600 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7fa8a137-a2d6-11ed-b63b-5f92e7d2e73a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SyRUAm/cHRaiZzLVhUFT09Xd8ko0DaHnNBubjdzjLI3pbXVNb1ip5qV1V7sqUEoGLmBupkyd9u9h98SN7BjbG5eQncvb06uEfUx6R83F3n9d7lF480A8gcgGEhb8z+qgj5s7BPXt0LnwuYQkNo/Ks40lRUJOQXnV1k087b7VuyNjT4LQcKTqrD2GktdAS3WLUF7VsF2C/xCTlLPlaSjZqHrtLKadT5UdZbq2AQHqvgaFx/3O1fLaf9BN0dZTJMit7ED0nJJC26ZRNuUvf6hrKnEv/lUl1y3UtzvXdaR9OrCXf8j6VoAWT5pD3Tahdw2Lg9Q4JZPT3y15EVVL9vAUpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uBLNfq0kNGD8ONWUKgdnR9q15jFiaFT0XCVIzdVZEEQ=; b=HdSCxB4cmaEp3gMxkc7lZ8ajtDdppAjoNG4IAzFNPJAE7tudJjNsqnzeLsqgR8+BImrNgjA2wZ0SSlfaARnu+MkQyB4cEc/JBJQkq5u6YfhNQ+8uAzZYtTQYAP4RVhuiggbFqE6as4yudezNvREj6B7WdFDeEQ1DvMp1Q3v4GQzzjf/edYbPfl7VTeMdrrFyZbQ5ggU93UDbMh+xUC+G2NNJlUHMTebYRRYaBu22ChoIBYza8Z0GtnLcjLe3QWJcJMIvDEakKGvxlBojMsHHcaEtTY6F6Uy+bylZN4gleVQMecwOKXOVNzd6zf1F5Civ7TsQwgHw/YEmh7Xe011gVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uBLNfq0kNGD8ONWUKgdnR9q15jFiaFT0XCVIzdVZEEQ=; b=rE0oexAgbSG2eNPfXT3Qm+4P6dIxL7KP1I7Zs/fBEEEgbjScC+rdvUgyAFEXIlvchlCfq2u+iFvY4AWReIHBDmWoIPpyPYETbPYsoZD+n2xx95kFTdZZbFO6N5uK4ztld8dihtuRt0OpNM/VGN1vdlBYNSa+EVbxGINd9D85oQE= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Michal Orzel To: CC: Michal Orzel , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , , Ayan Kumar Halder , "Julien Grall" Subject: [PATCH v2 1/2] xen/arm: Move kernel_uimage_probe definition after kernel_decompress Date: Thu, 2 Feb 2023 09:49:04 +0100 Message-ID: <20230202084905.6950-2-michal.orzel@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230202084905.6950-1-michal.orzel@amd.com> References: <20230202084905.6950-1-michal.orzel@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT116:EE_|MN2PR12MB4566:EE_ X-MS-Office365-Filtering-Correlation-Id: c8f362ae-692a-4ced-581a-08db04fa61fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6YaMZPcBI8LpF1WcIFBuro0VZRysGKakmq/xz/mJv+ArpSo1zJqrh32QjBcq19dhf46tqgcJ/ItzvrbN/u1yOrRX1lNbWKYKWOWc8gjnXqnTqAjUDf/BF76yauoV5DKJdEiVm13XHXNOh7hf4f0QHV/sxFd+c3W4RDIlAVR6AEMDpSmQKzhIkQ4bEXmS5iK1ygd/PTamSNrbUH/lL+rlYK4QcXtpGSXwbeRVZgmeG1O384eTHgkpcgvaB5LA+XpKQdx3enkGhQO/VtVmJToGcMbNBuDmjeB2rlqNqdhBKfbEYmHDFCcE0qkXtKuq+ZM3WJxCmTi29s+JWZdrcO6UbpZRslXW82FR8hC5F62pA5QkV4mm1hhArZjmgVmSvIz6tASCAYWq1iRBXCVMgLigC4SekuQ2SUWYwuLHwtalgPbhZ2Y0YhWqqPFoc/xSZfSZr0o9aG3O0aPN97lI5DlBFPhuzL6kA8NcGAMJFYyrfN/VL0lPjOLs7Z0U7adQymKEwUqSGAz8/YBHncWrBJDcszFqpqoehUP529bF5x9tMOP5xLEgh0N85YfJhiQpuW62UREsqCQAwbl3RFQZKQrH0yUi2hCG68A0tXFfmyoKfqgx0xks8BN+S6FrO6AwZGlmkELcnpplo9NCy9WrIi/AwlaLQf04kUFDXK6qweJ2HfH/AYEVS06FFlNjvA9ZLEvPKlJ3dXorPwSpY18+swUeUfRNY8PHSoVF3IAUhwT/BZU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(136003)(346002)(39860400002)(396003)(376002)(451199018)(40470700004)(36840700001)(46966006)(2616005)(336012)(40460700003)(40480700001)(82310400005)(36756003)(36860700001)(86362001)(82740400003)(8936002)(5660300002)(316002)(44832011)(356005)(54906003)(41300700001)(426003)(47076005)(81166007)(2906002)(83380400001)(6916009)(1076003)(4326008)(186003)(8676002)(478600001)(26005)(6666004)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2023 08:49:23.4720 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8f362ae-692a-4ced-581a-08db04fa61fa X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT116.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4566 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1675327811655100001 Content-Type: text/plain; charset="utf-8" In a follow-up patch, we will be calling kernel_decompress function from within kernel_uimage_probe to support booting compressed images with u-boot header. Therefore, move the kernel_uimage_probe definition after kernel_decompress so that the latter is visible to the former. No functional change intended. Signed-off-by: Michal Orzel Reviewed-by: Ayan Kumar Halder Acked-by: Julien Grall --- Changes in v2: - add Rb and Ab --- xen/arch/arm/kernel.c | 146 +++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 36081e73f140..068fbf88e492 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -186,6 +186,79 @@ static void __init kernel_zimage_load(struct kernel_in= fo *info) iounmap(kernel); } =20 +static __init uint32_t output_length(char *image, unsigned long image_len) +{ + return *(uint32_t *)&image[image_len - 4]; +} + +static __init int kernel_decompress(struct bootmodule *mod) +{ + char *output, *input; + char magic[2]; + int rc; + unsigned int kernel_order_out; + paddr_t output_size; + struct page_info *pages; + mfn_t mfn; + int i; + paddr_t addr =3D mod->start; + paddr_t size =3D mod->size; + + if ( size < 2 ) + return -EINVAL; + + copy_from_paddr(magic, addr, sizeof(magic)); + + /* only gzip is supported */ + if ( !gzip_check(magic, size) ) + return -EINVAL; + + input =3D ioremap_cache(addr, size); + if ( input =3D=3D NULL ) + return -EFAULT; + + output_size =3D output_length(input, size); + kernel_order_out =3D get_order_from_bytes(output_size); + pages =3D alloc_domheap_pages(NULL, kernel_order_out, 0); + if ( pages =3D=3D NULL ) + { + iounmap(input); + return -ENOMEM; + } + mfn =3D page_to_mfn(pages); + output =3D __vmap(&mfn, 1 << kernel_order_out, 1, 1, PAGE_HYPERVISOR, = VMAP_DEFAULT); + + rc =3D perform_gunzip(output, input, size); + clean_dcache_va_range(output, output_size); + iounmap(input); + vunmap(output); + + if ( rc ) + { + free_domheap_pages(pages, kernel_order_out); + return rc; + } + + mod->start =3D page_to_maddr(pages); + mod->size =3D output_size; + + /* + * Need to free pages after output_size here because they won't be + * freed by discard_initial_modules + */ + i =3D PFN_UP(output_size); + for ( ; i < (1 << kernel_order_out); i++ ) + free_domheap_page(pages + i); + + /* + * Free the original kernel, update the pointers to the + * decompressed kernel + */ + fw_unreserved_regions(addr, addr + size, init_domheap_pages, 0); + + return 0; +} + /* * Uimage CPU Architecture Codes */ @@ -289,79 +362,6 @@ static int __init kernel_uimage_probe(struct kernel_in= fo *info, return 0; } =20 -static __init uint32_t output_length(char *image, unsigned long image_len) -{ - return *(uint32_t *)&image[image_len - 4]; -} - -static __init int kernel_decompress(struct bootmodule *mod) -{ - char *output, *input; - char magic[2]; - int rc; - unsigned int kernel_order_out; - paddr_t output_size; - struct page_info *pages; - mfn_t mfn; - int i; - paddr_t addr =3D mod->start; - paddr_t size =3D mod->size; - - if ( size < 2 ) - return -EINVAL; - - copy_from_paddr(magic, addr, sizeof(magic)); - - /* only gzip is supported */ - if ( !gzip_check(magic, size) ) - return -EINVAL; - - input =3D ioremap_cache(addr, size); - if ( input =3D=3D NULL ) - return -EFAULT; - - output_size =3D output_length(input, size); - kernel_order_out =3D get_order_from_bytes(output_size); - pages =3D alloc_domheap_pages(NULL, kernel_order_out, 0); - if ( pages =3D=3D NULL ) - { - iounmap(input); - return -ENOMEM; - } - mfn =3D page_to_mfn(pages); - output =3D __vmap(&mfn, 1 << kernel_order_out, 1, 1, PAGE_HYPERVISOR, = VMAP_DEFAULT); - - rc =3D perform_gunzip(output, input, size); - clean_dcache_va_range(output, output_size); - iounmap(input); - vunmap(output); - - if ( rc ) - { - free_domheap_pages(pages, kernel_order_out); - return rc; - } - - mod->start =3D page_to_maddr(pages); - mod->size =3D output_size; - - /* - * Need to free pages after output_size here because they won't be - * freed by discard_initial_modules - */ - i =3D PFN_UP(output_size); - for ( ; i < (1 << kernel_order_out); i++ ) - free_domheap_page(pages + i); - - /* - * Free the original kernel, update the pointers to the - * decompressed kernel - */ - fw_unreserved_regions(addr, addr + size, init_domheap_pages, 0); - - return 0; -} - #ifdef CONFIG_ARM_64 /* * Check if the image is a 64-bit Image. --=20 2.25.1 From nobody Mon May 13 17:08:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1675327821; cv=pass; d=zohomail.com; s=zohoarc; b=KdYORMyXvjyXU6ffCSfaFIUnljyYQJ1Y+uvXm1IPVDDzUjljcmIw/5jZzlFdWquHSSQFCkLyJbbVOkh/3BpQGmB0V6BdDnRFmGnyydLVIW3fjFs3tJdcQc9GuaQvFus1al2N/PwKWWpWjPGl9OlkRzvZwwcsRY5jcCRy76DDk+8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675327821; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=miuqtHseJ/K4LAnHtbyabXWBQMCXuBv77extmOJaVLI=; b=nURpR33mSq84JRBsGTM3VCR6XO2WB2OhDSO+nH4Hk4A28gobiQ8Wo2XGEmh3nKLkCmZCzWzN3GWRmeELDcXT0OFh7txJO92IZNZOJ2O0VHs2/nBFpVyglfnKjRHVk13nb+LHETjXbgy4Tg7oF73zN8KQyuDNR3LVvyHkRprAEsU= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1675327821425445.94237898050415; Thu, 2 Feb 2023 00:50:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.488597.756746 (Exim 4.92) (envelope-from ) id 1pNVHh-0004gt-Bp; Thu, 02 Feb 2023 08:49:33 +0000 Received: by outflank-mailman (output) from mailman id 488597.756746; Thu, 02 Feb 2023 08:49:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pNVHh-0004gi-8J; Thu, 02 Feb 2023 08:49:33 +0000 Received: by outflank-mailman (input) for mailman id 488597; Thu, 02 Feb 2023 08:49:31 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pNVHf-0004Po-40 for xen-devel@lists.xenproject.org; Thu, 02 Feb 2023 08:49:31 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2062b.outbound.protection.outlook.com [2a01:111:f400:7e8a::62b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 807f5548-a2d6-11ed-b63b-5f92e7d2e73a; Thu, 02 Feb 2023 09:49:29 +0100 (CET) Received: from BN0PR07CA0027.namprd07.prod.outlook.com (2603:10b6:408:141::29) by MN2PR12MB4144.namprd12.prod.outlook.com (2603:10b6:208:15f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.27; Thu, 2 Feb 2023 08:49:26 +0000 Received: from BN8NAM11FT100.eop-nam11.prod.protection.outlook.com (2603:10b6:408:141:cafe::89) by BN0PR07CA0027.outlook.office365.com (2603:10b6:408:141::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.25 via Frontend Transport; Thu, 2 Feb 2023 08:49:26 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT100.mail.protection.outlook.com (10.13.177.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6064.27 via Frontend Transport; Thu, 2 Feb 2023 08:49:25 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 2 Feb 2023 02:49:25 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 2 Feb 2023 02:49:24 -0600 Received: from XIR-MICHALO-L1.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 2 Feb 2023 02:49:23 -0600 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 807f5548-a2d6-11ed-b63b-5f92e7d2e73a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kuVJthUGCa09GTKS0EdP6f4hTLpeMnnkTLSwgnm826TtFbAyRU+B8pxNsZh43Hn6Bggt85iiWSXz+LjqjumrNG4c04oRNXAJeXRjwniUNrim1QhCFbrSAVkF9gd+7CNsWpSt4VrPQx+dI+XmTwVztbDF8aEiznnQd9ZZP/oHg7Jnmw0Ep8Eyl0rdYVB5OpndnK89dC9Q1PL4oOvFSi94Cf3kUyOuW9IWOD5EWIGmIxDoPFYlOWIEQS6U6bI/a5hIFVB5Vd6TJaXnhieYV5znmgmB9VTsA6ymbSdSWv/qAgj0XRUVrTUn7FwWoPMydtz4D2sg7SGlvR4zTjlGWmdPqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=miuqtHseJ/K4LAnHtbyabXWBQMCXuBv77extmOJaVLI=; b=WfhLy2kk80raGa+6whBBrfBbW5XRL8UIZAnPnYXjFYnTvkzy83SpmI7wk2Lot7VLdcoSRCIIrqNXo30zcuPNm8I10uxmUMI8RS31+Pf3UwSEoSfUrkAmfqkavJwe0J7BUn/p7nBsfG/er2aWByMO+dcf5OlB7y3UFOoLH0EGl9IxDZp7CKx0R+wywQhTcaAMsgCoj8deqy2IkPuUjF0jLh8gXnz3HcOOSnjZpb3WB5sh7ZEowc79/7o02mVoqb6IZOPgVzA0STR2G02DqRw4tNLEphNLKDVrrQAD0vQz/riT6wm5hfdobv5g+320061bKVr2ISsBp01xZDyGqA9YpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=miuqtHseJ/K4LAnHtbyabXWBQMCXuBv77extmOJaVLI=; b=u4leEexpxx66l2PnCRg+IZAoMYDUDbU/j70UFFRQqZFWx7aXMaE5N0IzIBU5EGKYNgTfN+UBf0B3IHLIiNImLoOYCEjQa7HUhfMWWSOR2Z8N7W7kbl3X/GzUl+CMFA1U8iDSinWDQFkQeENtvEMlEknftWPc8qlXvXabyEg5PiI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Michal Orzel To: CC: Michal Orzel , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Subject: [PATCH v2 2/2] xen/arm: Add support for booting gzip compressed uImages Date: Thu, 2 Feb 2023 09:49:05 +0100 Message-ID: <20230202084905.6950-3-michal.orzel@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230202084905.6950-1-michal.orzel@amd.com> References: <20230202084905.6950-1-michal.orzel@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT100:EE_|MN2PR12MB4144:EE_ X-MS-Office365-Filtering-Correlation-Id: 4668ee20-1fd5-4fcb-dfc4-08db04fa6323 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QKH7W3GkJDN+g6OsPSdY3ZpHlhljVW4Yqaczo3RUqtl5u5y3CdvhJIPxCeUMiweKd6czLlHcU9o9UeVQYbhBCj3064TkBRGFafE0Jv8G+3b8ltZU6Foc04Hu/CL/goEfFji8N+XPzdaICndsbTElI2ZiSALRi0iuovWrwfDd08AQw2s/zUIk0/g1L2gj/vtfQMe2EVyvliLAc0at1TvOk5D/nB57mflE23LjeI2Qlc6K+MSU5+YYHlKyHrshRMB3cGLv/Hu3psyEiTBUQEx1Hu2+D6/Ss1H5+IKgVVeQ5ycUWE2JmhhpipJQXfV6v/yljS8nPXRvFmfRBvEbrYVwkFRgqmBQP9cpC4Z5RWzgjzH7l9Ej+AXgRoN6c9uH5ZtzkbQ0gkszit88sOcU/YzTeQfcyddqPmppa/TrXM6X8sFPqXVsN9oAWc0MQiktaN1LsQ2Inkd7H/hVL1ClErX2pKWTayZ4sxYP0bO52JT4wQt32v2fLSrTSBEMI1SEG+sd5NEDWt5fNrLSz/GLcMXt0nbfdWx5s8PN7W3VKoCdF1AV1X3zPb1/kQhhJGtGJ4llEsC/5B83gtxT/atKx8WHhdEKgWAv1yOX3aSzTBuFy3YGDY2m+ga7r7Z9psssbO1HwIPSqaFqucvIbOArKh9lvFBg2qmD++n12Sp7uCK0P7GDfxFOh+NhMsJCvThr0gztt204Nik4cXKTZERgqZGLX5F0XbEt6cZwH9yW15GBcZo= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(346002)(136003)(396003)(39860400002)(376002)(451199018)(36840700001)(40470700004)(46966006)(40460700003)(36860700001)(478600001)(316002)(54906003)(186003)(26005)(36756003)(1076003)(6666004)(82310400005)(86362001)(5660300002)(2906002)(44832011)(4326008)(6916009)(70586007)(70206006)(8676002)(41300700001)(8936002)(40480700001)(426003)(83380400001)(336012)(2616005)(47076005)(356005)(81166007)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2023 08:49:25.4375 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4668ee20-1fd5-4fcb-dfc4-08db04fa6323 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT100.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4144 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1675327823584100001 Content-Type: text/plain; charset="utf-8" At the moment, Xen does not support booting gzip compressed uImages. This is because we are trying to decompress the kernel before probing the u-boot header. This leads to a failure as the header always appears at the top of the image (and therefore obscuring the gzip header). Move the call to kernel_uimage_probe before kernel_decompress and make the function self-containing by taking the following actions: - take a pointer to struct bootmodule as a parameter, - check the comp field of a u-boot header to determine compression type, - in case of compressed image, call kernel_decompress passing uImage header size as an offset to gzip header, - set up zimage.{kernel_addr,len} accordingly, - return -ENOENT in case of a u-boot header not found to distinguish it amongst other return values and make it the only case for falling through to try to probe other image types. Modify kernel_decompress to take an additional parameter being an offset to a gzip header from start address. This is needed so that a function can first operate on a region containing actually compressed kernel (in case of compressed uImage, size of u-boot header is an offset to a gzip header) and then at the end pass the entire region (as it was before taking an offs= et into account) to fw_unreserved_regions for freeing. This approach avoids splitting the uImage probing into 2 stages (executed before and after decompression) which otherwise would be necessary to properly parse header, update boot module start and size before decompression and update zimage.{kernel_addr,len} afterwards. Remove the limitation from the booting.txt documentation. Signed-off-by: Michal Orzel Reviewed-by: Julien Grall --- Changes in v2: - modify kernel_decompress to take an offset to gzip header --- docs/misc/arm/booting.txt | 3 -- xen/arch/arm/kernel.c | 81 ++++++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/docs/misc/arm/booting.txt b/docs/misc/arm/booting.txt index bd7bfe7f284a..02f7bb65ec6d 100644 --- a/docs/misc/arm/booting.txt +++ b/docs/misc/arm/booting.txt @@ -50,9 +50,6 @@ Also, it is to be noted that if user provides the legacy = image header on top of zImage or Image header, then Xen uses the attributes of legacy image header to determine the load address, entry point, etc. =20 -Known limitation: compressed kernels with a uboot headers are not -working. - =20 Firmware/bootloader requirements -------------------------------- diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 068fbf88e492..7dd082b5772c 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -191,7 +191,7 @@ static __init uint32_t output_length(char *image, unsig= ned long image_len) return *(uint32_t *)&image[image_len - 4]; } =20 -static __init int kernel_decompress(struct bootmodule *mod) +static __init int kernel_decompress(struct bootmodule *mod, uint32_t offse= t) { char *output, *input; char magic[2]; @@ -204,6 +204,17 @@ static __init int kernel_decompress(struct bootmodule = *mod) paddr_t addr =3D mod->start; paddr_t size =3D mod->size; =20 + if ( size < offset ) + return -EINVAL; + + /* + * It might be that gzip header does not appear at the start address + * (e.g. in case of compressed uImage) so take into account offset to + * gzip header. + */ + addr +=3D offset; + size -=3D offset; + if ( size < 2 ) return -EINVAL; =20 @@ -250,6 +261,14 @@ static __init int kernel_decompress(struct bootmodule = *mod) for ( ; i < (1 << kernel_order_out); i++ ) free_domheap_page(pages + i); =20 + /* + * When freeing the kernel, we need to pass the module start address a= nd + * size as they were before taking an offset to gzip header into accou= nt, + * so that the entire region will be freed. + */ + addr -=3D offset; + size +=3D offset; + /* * Free the original kernel, update the pointers to the * decompressed kernel @@ -265,11 +284,14 @@ static __init int kernel_decompress(struct bootmodule= *mod) #define IH_ARCH_ARM 2 /* ARM */ #define IH_ARCH_ARM64 22 /* ARM64 */ =20 +/* uImage Compression Types */ +#define IH_COMP_GZIP 1 + /* * Check if the image is a uImage and setup kernel_info */ static int __init kernel_uimage_probe(struct kernel_info *info, - paddr_t addr, paddr_t size) + struct bootmodule *mod) { struct { __be32 magic; /* Image Header Magic Number */ @@ -287,6 +309,8 @@ static int __init kernel_uimage_probe(struct kernel_inf= o *info, } uimage; =20 uint32_t len; + paddr_t addr =3D mod->start; + paddr_t size =3D mod->size; =20 if ( size < sizeof(uimage) ) return -EINVAL; @@ -294,13 +318,21 @@ static int __init kernel_uimage_probe(struct kernel_i= nfo *info, copy_from_paddr(&uimage, addr, sizeof(uimage)); =20 if ( be32_to_cpu(uimage.magic) !=3D UIMAGE_MAGIC ) - return -EINVAL; + return -ENOENT; =20 len =3D be32_to_cpu(uimage.size); =20 if ( len > size - sizeof(uimage) ) return -EINVAL; =20 + /* Only gzip compression is supported. */ + if ( uimage.comp && uimage.comp !=3D IH_COMP_GZIP ) + { + printk(XENLOG_ERR + "Unsupported uImage compression type %"PRIu8"\n", uimage.co= mp); + return -EOPNOTSUPP; + } + info->zimage.start =3D be32_to_cpu(uimage.load); info->entry =3D be32_to_cpu(uimage.ep); =20 @@ -330,8 +362,27 @@ static int __init kernel_uimage_probe(struct kernel_in= fo *info, return -EINVAL; } =20 - info->zimage.kernel_addr =3D addr + sizeof(uimage); - info->zimage.len =3D len; + if ( uimage.comp ) + { + int rc; + + /* + * In case of a compressed uImage, the gzip header is right after + * the u-boot header, so pass sizeof(uimage) as an offset to gzip + * header. + */ + rc =3D kernel_decompress(mod, sizeof(uimage)); + if ( rc ) + return rc; + + info->zimage.kernel_addr =3D mod->start; + info->zimage.len =3D mod->size; + } + else + { + info->zimage.kernel_addr =3D addr + sizeof(uimage); + info->zimage.len =3D len; + } =20 info->load =3D kernel_zimage_load; =20 @@ -561,8 +612,22 @@ int __init kernel_probe(struct kernel_info *info, printk("Loading ramdisk from boot module @ %"PRIpaddr"\n", info->initrd_bootmodule->start); =20 - /* if it is a gzip'ed image, 32bit or 64bit, uncompress it */ - rc =3D kernel_decompress(mod); + /* + * uImage header always appears at the top of the image (even compress= ed), + * so it needs to be probed first. Note that in case of compressed uIm= age, + * kernel_decompress is called from kernel_uimage_probe making the fun= ction + * self-containing (i.e. fall through only in case of a header not fou= nd). + */ + rc =3D kernel_uimage_probe(info, mod); + if ( rc !=3D -ENOENT ) + return rc; + + /* + * If it is a gzip'ed image, 32bit or 64bit, uncompress it. + * At this point, gzip header appears (if at all) at the top of the im= age, + * so pass 0 as an offset. + */ + rc =3D kernel_decompress(mod, 0); if ( rc && rc !=3D -EINVAL ) return rc; =20 @@ -570,8 +635,6 @@ int __init kernel_probe(struct kernel_info *info, rc =3D kernel_zimage64_probe(info, mod->start, mod->size); if (rc < 0) #endif - rc =3D kernel_uimage_probe(info, mod->start, mod->size); - if (rc < 0) rc =3D kernel_zimage32_probe(info, mod->start, mod->size); =20 return rc; --=20 2.25.1