From patchwork Tue Mar 19 20:58:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13597062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4DF8C54E71 for ; Tue, 19 Mar 2024 20:59:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.695610.1085490 (Exim 4.92) (envelope-from ) id 1rmgY5-0007yI-5O; Tue, 19 Mar 2024 20:59:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 695610.1085490; Tue, 19 Mar 2024 20:59:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rmgY5-0007yB-2j; Tue, 19 Mar 2024 20:59:05 +0000 Received: by outflank-mailman (input) for mailman id 695610; Tue, 19 Mar 2024 20:59:04 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rmgY4-0007xt-LO for xen-devel@lists.xenproject.org; Tue, 19 Mar 2024 20:59:04 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20600.outbound.protection.outlook.com [2a01:111:f403:2009::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 83eae5a2-e633-11ee-afdd-a90da7624cb6; Tue, 19 Mar 2024 21:59:03 +0100 (CET) Received: from DS7PR05CA0010.namprd05.prod.outlook.com (2603:10b6:5:3b9::15) by PH7PR12MB6720.namprd12.prod.outlook.com (2603:10b6:510:1b3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Tue, 19 Mar 2024 20:59:00 +0000 Received: from DS2PEPF0000343F.namprd02.prod.outlook.com (2603:10b6:5:3b9:cafe::78) by DS7PR05CA0010.outlook.office365.com (2603:10b6:5:3b9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Tue, 19 Mar 2024 20:59:00 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by DS2PEPF0000343F.mail.protection.outlook.com (10.167.18.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Tue, 19 Mar 2024 20:58:59 +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.2507.35; Tue, 19 Mar 2024 15:58:58 -0500 Received: from fedora.mshome.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Tue, 19 Mar 2024 15:58:57 -0500 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: 83eae5a2-e633-11ee-afdd-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QP4kE3KnwdB6lhcrw2PbDmWLMdjKfDzlEXaqY18R1HCVWfZvT371alStIsDrIK7/eH8QyygOT3DntguKx+1yMipEIqDPnk2x5dsH7kaq2urbezQ3vlzz48Bmeb3mRW2rfSbquaqN9HLcnfjVbe7xbBk/8Imo+dbJmThGwvCv1RL2sHKW9jJhKgLXFkTqKtwxerehKA54TIISM2P2VcLlYJul99pi/lRAg0pl2Fww0tK72cVeIwWyoBazjp6yRXr41oawEf/acb6tp/AuMLjCeCR53pqNuDSLZttY1fuKPxj/H4U5Qme3yynhr9IWO3lpyvN93Heyoy/qCcGC9moylg== 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=lvOehq1EJKjZfWXBSzZg1ZZ1p5IUUk1AykmRfeyalZA=; b=PNCHOtDTdMxWeRKFvqUNxWU5nbQ+c+vQ9tn5TwxRenqmNtjD9wycLeGwRmzP5sDXm3wYF5Cuhu131QR2SOV0OPkml07VXm3IFCT9EzbU3YqR6Z+xaYZ2ZirtNqLrlg10sSCEUieTi0kEq0Nxj3MPMUvHyStmjZxwA+tB2Q2wN4PKreyOLg4iWTunA9kKq4wRgJJmaN8QFYhWP5h1DDPJJWSS8z4L//FbLSimY2VXU3rvk4PRXw+kIVLPJTcRoGXZ+Koa8aXviAJOgFTDgSAAGI6FUgdQrm+0Sd0QMjtdobuEoOk3nbPwGTCQfQSOYFBke/no4nxHBXOZ+cJ38x+Kgw== 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 (0) 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=lvOehq1EJKjZfWXBSzZg1ZZ1p5IUUk1AykmRfeyalZA=; b=dFwlsOiV0hwdksokGnZ4VQqmaIBeTPFwnS+lpUu6pL3/JlXCNC8Jn7NHYeIsKm7Df+hMPzoJXDWsKF+FeRZ4BX/RBdxuFzGDkk407MgiUfpH46+sYjrfhNBwsghQBY29+MWRbkVmo5c2O3wx5LtQhohvzkCxCnzI0ho4wXgtLNI= 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 (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: Jason Andryuk To: CC: Jason Andryuk , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu Subject: [PATCH v3 1/3] Revert "xen/x86: bzImage parse kernel_alignment" Date: Tue, 19 Mar 2024 16:58:47 -0400 Message-ID: <20240319205849.115884-2-jason.andryuk@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240319205849.115884-1-jason.andryuk@amd.com> References: <20240319205849.115884-1-jason.andryuk@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: jason.andryuk@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF0000343F:EE_|PH7PR12MB6720:EE_ X-MS-Office365-Filtering-Correlation-Id: e1b8378e-132a-4a54-f0fd-08dc4857669a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r8OnCdXJb+tokcrlhn8iiEY+4Fun5Gr7Fg3nCYPHg5/CIaOrIJiqiuCcitCL/jifBkrffIJEvH9xt7w0GYklEghfFC3WZlEJov1UCm88RVXzkP6B+XxrizgSJfvY9CvMk9cKlfxA6+XEfpAfrhrbW9PfngFJC+mtkzHk7Iz6Bshedvtz4Rkh4XCCWRRz6IUyGDogAPV8juC2+gkXebA9cudyWYmRn6pPhMPU3GZwQZhC7qEbR8tot0Lb2zJHLoPif89xonVpk4exUpZqC9Fe3Evn15Xs7yA071uDjAeG2fFxGNRJkhYGPZcJdk0rFhnx9WSCwYTGMoNA/BSEegth7Y7uPCfc/t2Ql6qXsQAni+jPnpBKygCo7Ee+f4n+PwV7UDRzspCtEctH5s4weKDs32fGPplIVSsBv5LN6ZjM81YfExpLoF7RhNrC9iYvcviGYdrPmq0Cb4QG/rlA5lj/zmyWQSLWzmlhmGNtEVZB8bjw92kx5GPitY3RbjBndbiV7oCU2omdIwUcCkM2JZfWvDvruDqAD/7fjIHVJw6VGxN/Y5yVBAwd+i57eBU/sSPfkdfHiCctw0UNUUN96HrDd7GFIIgZnTMtoMW/O9pdn7TCSabMuH47/qgXkkktuBpn2kPZC/HJlhxBIFiJH1O9VmNTtzRGlhyHTQ/mQT/vxbPP0UswNm1tkHTYCtWPqKHIfy8cKEqNXUg00nDqdxBy+xDq1kVpfk9Qmy+vsWR3nHvRohIPNWm+62IcutNQKc4p 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:(13230031)(376005)(1800799015)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2024 20:58:59.9771 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e1b8378e-132a-4a54-f0fd-08dc4857669a 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: DS2PEPF0000343F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6720 A new ELF note will specify the alignment for a relocatable PVH kernel. ELF notes are suitable for vmlinux and other ELF files, so this Linux-specific bzImage parsing in unnecessary. This reverts commit c44cac229067faeec8f49247d1cf281723ac2d40. Signed-off-by: Jason Andryuk --- xen/arch/x86/bzimage.c | 4 +--- xen/arch/x86/hvm/dom0_build.c | 4 +--- xen/arch/x86/include/asm/bzimage.h | 2 +- xen/arch/x86/pv/dom0_build.c | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/bzimage.c b/xen/arch/x86/bzimage.c index 0f4cfc49f7..ac4fd428be 100644 --- a/xen/arch/x86/bzimage.c +++ b/xen/arch/x86/bzimage.c @@ -105,7 +105,7 @@ unsigned long __init bzimage_headroom(void *image_start, } int __init bzimage_parse(void *image_base, void **image_start, - unsigned long *image_len, unsigned int *align) + unsigned long *image_len) { struct setup_header *hdr = (struct setup_header *)(*image_start); int err = bzimage_check(hdr, *image_len); @@ -118,8 +118,6 @@ int __init bzimage_parse(void *image_base, void **image_start, { *image_start += (hdr->setup_sects + 1) * 512 + hdr->payload_offset; *image_len = hdr->payload_length; - if ( align ) - *align = hdr->kernel_alignment; } if ( elf_is_elfbinary(*image_start, *image_len) ) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index bbae8a5645..0ceda4140b 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -548,14 +548,12 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, struct elf_binary elf; struct elf_dom_parms parms; paddr_t last_addr; - unsigned int align = 0; struct hvm_start_info start_info = { 0 }; struct hvm_modlist_entry mod = { 0 }; struct vcpu *v = d->vcpu[0]; int rc; - rc = bzimage_parse(image_base, &image_start, &image_len, &align); - if ( rc != 0 ) + if ( (rc = bzimage_parse(image_base, &image_start, &image_len)) != 0 ) { printk("Error trying to detect bz compressed kernel\n"); return rc; diff --git a/xen/arch/x86/include/asm/bzimage.h b/xen/arch/x86/include/asm/bzimage.h index 2e04f5cc7b..7ed69d3910 100644 --- a/xen/arch/x86/include/asm/bzimage.h +++ b/xen/arch/x86/include/asm/bzimage.h @@ -6,6 +6,6 @@ unsigned long bzimage_headroom(void *image_start, unsigned long image_length); int bzimage_parse(void *image_base, void **image_start, - unsigned long *image_len, unsigned int *align); + unsigned long *image_len); #endif /* __X86_BZIMAGE_H__ */ diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index e9fa8a9a82..d8043fa58a 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -416,7 +416,7 @@ int __init dom0_construct_pv(struct domain *d, d->max_pages = ~0U; - if ( (rc = bzimage_parse(image_base, &image_start, &image_len, NULL)) != 0 ) + if ( (rc = bzimage_parse(image_base, &image_start, &image_len)) != 0 ) return rc; if ( (rc = elf_init(&elf, image_start, image_len)) != 0 ) From patchwork Tue Mar 19 20:58:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13597064 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5B09EC54E71 for ; Tue, 19 Mar 2024 20:59:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.695611.1085500 (Exim 4.92) (envelope-from ) id 1rmgY9-0008He-HA; Tue, 19 Mar 2024 20:59:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 695611.1085500; Tue, 19 Mar 2024 20:59:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rmgY9-0008HU-Dw; Tue, 19 Mar 2024 20:59:09 +0000 Received: by outflank-mailman (input) for mailman id 695611; Tue, 19 Mar 2024 20:59:08 +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 1rmgY8-0007jV-Hg for xen-devel@lists.xenproject.org; Tue, 19 Mar 2024 20:59:08 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20601.outbound.protection.outlook.com [2a01:111:f403:200a::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 865926d3-e633-11ee-a1ee-f123f15fe8a2; Tue, 19 Mar 2024 21:59:07 +0100 (CET) Received: from CH2PR07CA0005.namprd07.prod.outlook.com (2603:10b6:610:20::18) by IA1PR12MB7736.namprd12.prod.outlook.com (2603:10b6:208:420::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.30; Tue, 19 Mar 2024 20:59:02 +0000 Received: from CH1PEPF0000A346.namprd04.prod.outlook.com (2603:10b6:610:20:cafe::ba) by CH2PR07CA0005.outlook.office365.com (2603:10b6:610:20::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.19 via Frontend Transport; Tue, 19 Mar 2024 20:59:02 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000A346.mail.protection.outlook.com (10.167.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Tue, 19 Mar 2024 20:59:02 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 19 Mar 2024 15:59:01 -0500 Received: from fedora.mshome.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Tue, 19 Mar 2024 15:59:00 -0500 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: 865926d3-e633-11ee-a1ee-f123f15fe8a2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IBzRTvisDlefOi9ZyMK7LQIdFVUzW/fGjGCj4THYmsSQJ3jhYb5yVrqWiPDeziDY0w5kX4sQfpmvtchL180JErnKNGZlCA6177rgwVT3ZdKr3/67VBA6yHY7tnW8O2aAkwvVs98W7xE8YQ65LA1ynUTPXrXdmQQNY2MgoTUF8OCssc8oUE8EqaR/38IxkkPH1hs0ur3Wxg1IgDuWUZJqn7K0N7ws7GQuGh7tgnOB+rycM8AfmjtLIaySly8H6f4dnP5QEgJhQKfKAQvgIrdsOh1dvuvzpPYn6rGvyAAQKyUJdaF3ewLFaX84sDE8ZtiPxWDPyuDEhlyMFz/RAq4Wuw== 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=NDm0ZtVyDBysq2xkYmsebdtkUyX6X2/ReXcGS+SS/nU=; b=kwprMUzI8IFE5wjhqZDCqZtcY3a+sB8t9SUHJ+m3gfRtvfrhPoqodprbqXf+wOXmT8RpBRh9wcPGQLC39gtduH8Ln5/OjDKxfR4ALGAHqhvQbkc6uW+okAWOrIJ0nexrwZrAJ9n65ERKAMMpaXckXPlsACiCFVFMnF79S12M7rrMiP5RyEqQ87TbHpYKh/j2fgyj1xmVNiYrvI/o2g6/230+f4/sz08epA0tZZj3zoFMZhzK/3n88o/JHWLMoP4CNGCQzeEF4zkL49lKef9vpS3bJfbCKPGLYpDsB8NwUanbXsZQ16scJRQ6OSQHiQ7PCeCe2d0dsT4IaunQgtM92Q== 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 (0) 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=NDm0ZtVyDBysq2xkYmsebdtkUyX6X2/ReXcGS+SS/nU=; b=XJlX0xIalPXa2OCZY/7xPbtPOtTvKRGDSQF3ScK9BxU9T+e7w3toQKCIoaas50Xwhbv0mqVC4MjoPKJZwkIw6lsRSoQL2ZyHCsXxNc2CmZ2iDEhqLpbOKZfyiXOUOn32JuGyndr5XFx5qzDPBQTaR9GzF+9OfU6FDRwknOPOG3w= 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 (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=SATLEXMB04.amd.com; pr=C From: Jason Andryuk To: CC: Jason Andryuk , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , "Stefano Stabellini" , Wei Liu Subject: [PATCH v3 2/3] libelf: Expand ELF note printing Date: Tue, 19 Mar 2024 16:58:48 -0400 Message-ID: <20240319205849.115884-3-jason.andryuk@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240319205849.115884-1-jason.andryuk@amd.com> References: <20240319205849.115884-1-jason.andryuk@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: jason.andryuk@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A346:EE_|IA1PR12MB7736:EE_ X-MS-Office365-Filtering-Correlation-Id: 955bdd22-30f8-4648-08f7-08dc4857680f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aPMiu3QItUiwzdgKym7VRj33rEQPotKrYMRnIbvy6DQt9e/SGYPVNXoSC586xV0Zen2Q8ZannXTJcLbfrIFsO6vAjE2LusAbUvxQBXVuzlEvhVVIDWybiLw8LahdyoQF/AT57kjy70D4EZh5VU0c9BGRoBCpXruB6IYa054TYlen9UG8J3URqORCyIbre2X5fXHqPyVTyCArcVkRbwVBn8sr82WEk6FJXqnGIIVDoblqzPeJ3RF/Z/ODdPXkXVRyvGGU0O8A88f9IxD883fQ2PCS8jESLQ8RRs0eatK7O9ORJaqE6wuGyeGv/jlM6WtXTFjeWnhyFg+yMgqeOfy6GrkOFCtntWzCYngCwx5qA3cE3i1trfcszFK6C9Dbu9HNxCobdbzRCOsQ3MbMOBllHkBbblhOJttFR5LBYo8oH5o74DAjKHsIgsy9RgFV6mf3LnJVqPLEJt8II47lRzAERRwKrbDMO6q9v/rK7TP9L2OMYXzg2QmInNCbkxAHg1GZJmSw5XGnEi2RkGS4M4dQ1YHzy3M4/scVq39ZCioNlOp2WcHPdTDN2ISv6y7YXF1Tk5aLGk4dXU7/q1Y3eLMByeEsXThUvPe8vQjwjtG+x34E02ZFg0pXWAGZbExUWBtvWvr39rkOMIoTTSjWuh8kTMpeCxuYg3nTSUpJ9KLoiIB3e+oHhGsdYKRkXO0OcPC8ZWaeOf30EDLmai9L1sWQr76ol9jNPi5hb06R/O42HyZ2Hl+BGwYIR3NxSSPF6zN6 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400014)(36860700004)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2024 20:59:02.4313 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 955bdd22-30f8-4648-08f7-08dc4857680f 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000A346.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7736 The XEN_ELFNOTE_L1_MFN_VALID is an array of pairs of values, but it is printed as: (XEN) ELF: note: L1_MFN_VALID = 0 This is a limitation of only printing either string or numeric values. Switch from the boolean to an enum which allows more flexibility in printing the values. Introduce ELFNOTE_NAME to only print the name without a value like: (XEN) ELF: note: L1_MFN_VALID Signed-off-by: Jason Andryuk Reviewed-by: Jan Beulich --- v3: Remove fatal size check Don't print values - just the name for presence --- xen/common/libelf/libelf-dominfo.c | 50 +++++++++++++++++------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/xen/common/libelf/libelf-dominfo.c b/xen/common/libelf/libelf-dominfo.c index a13a5e4db6..405510ead9 100644 --- a/xen/common/libelf/libelf-dominfo.c +++ b/xen/common/libelf/libelf-dominfo.c @@ -101,26 +101,30 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, /* *INDENT-OFF* */ static const struct { const char *name; - bool str; + enum { + ELFNOTE_INT, + ELFNOTE_STRING, + ELFNOTE_NAME, + } type; } note_desc[] = { - [XEN_ELFNOTE_ENTRY] = { "ENTRY", 0}, - [XEN_ELFNOTE_HYPERCALL_PAGE] = { "HYPERCALL_PAGE", 0}, - [XEN_ELFNOTE_VIRT_BASE] = { "VIRT_BASE", 0}, - [XEN_ELFNOTE_INIT_P2M] = { "INIT_P2M", 0}, - [XEN_ELFNOTE_PADDR_OFFSET] = { "PADDR_OFFSET", 0}, - [XEN_ELFNOTE_HV_START_LOW] = { "HV_START_LOW", 0}, - [XEN_ELFNOTE_XEN_VERSION] = { "XEN_VERSION", 1}, - [XEN_ELFNOTE_GUEST_OS] = { "GUEST_OS", 1}, - [XEN_ELFNOTE_GUEST_VERSION] = { "GUEST_VERSION", 1}, - [XEN_ELFNOTE_LOADER] = { "LOADER", 1}, - [XEN_ELFNOTE_PAE_MODE] = { "PAE_MODE", 1}, - [XEN_ELFNOTE_FEATURES] = { "FEATURES", 1}, - [XEN_ELFNOTE_SUPPORTED_FEATURES] = { "SUPPORTED_FEATURES", 0}, - [XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", 1}, - [XEN_ELFNOTE_L1_MFN_VALID] = { "L1_MFN_VALID", false }, - [XEN_ELFNOTE_SUSPEND_CANCEL] = { "SUSPEND_CANCEL", 0 }, - [XEN_ELFNOTE_MOD_START_PFN] = { "MOD_START_PFN", 0 }, - [XEN_ELFNOTE_PHYS32_ENTRY] = { "PHYS32_ENTRY", 0 }, + [XEN_ELFNOTE_ENTRY] = { "ENTRY", ELFNOTE_INT }, + [XEN_ELFNOTE_HYPERCALL_PAGE] = { "HYPERCALL_PAGE", ELFNOTE_INT }, + [XEN_ELFNOTE_VIRT_BASE] = { "VIRT_BASE", ELFNOTE_INT }, + [XEN_ELFNOTE_INIT_P2M] = { "INIT_P2M", ELFNOTE_INT }, + [XEN_ELFNOTE_PADDR_OFFSET] = { "PADDR_OFFSET", ELFNOTE_INT }, + [XEN_ELFNOTE_HV_START_LOW] = { "HV_START_LOW", ELFNOTE_INT }, + [XEN_ELFNOTE_XEN_VERSION] = { "XEN_VERSION", ELFNOTE_STRING }, + [XEN_ELFNOTE_GUEST_OS] = { "GUEST_OS", ELFNOTE_STRING }, + [XEN_ELFNOTE_GUEST_VERSION] = { "GUEST_VERSION", ELFNOTE_STRING }, + [XEN_ELFNOTE_LOADER] = { "LOADER", ELFNOTE_STRING }, + [XEN_ELFNOTE_PAE_MODE] = { "PAE_MODE", ELFNOTE_STRING }, + [XEN_ELFNOTE_FEATURES] = { "FEATURES", ELFNOTE_STRING }, + [XEN_ELFNOTE_SUPPORTED_FEATURES] = { "SUPPORTED_FEATURES", ELFNOTE_INT }, + [XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", ELFNOTE_STRING }, + [XEN_ELFNOTE_L1_MFN_VALID] = { "L1_MFN_VALID", ELFNOTE_NAME }, + [XEN_ELFNOTE_SUSPEND_CANCEL] = { "SUSPEND_CANCEL", ELFNOTE_INT }, + [XEN_ELFNOTE_MOD_START_PFN] = { "MOD_START_PFN", ELFNOTE_INT }, + [XEN_ELFNOTE_PHYS32_ENTRY] = { "PHYS32_ENTRY", ELFNOTE_INT }, }; /* *INDENT-ON* */ @@ -136,7 +140,7 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, return 0; } - if ( note_desc[type].str ) + if ( note_desc[type].type == ELFNOTE_STRING ) { str = elf_strval(elf, elf_note_desc(elf, note)); if (str == NULL) @@ -146,13 +150,17 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, parms->elf_notes[type].type = XEN_ENT_STR; parms->elf_notes[type].data.str = str; } - else + else if ( note_desc[type].type == ELFNOTE_INT ) { val = elf_note_numeric(elf, note); elf_msg(elf, "ELF: note: %s = %#" PRIx64 "\n", note_desc[type].name, val); parms->elf_notes[type].type = XEN_ENT_LONG; parms->elf_notes[type].data.num = val; } + else if ( note_desc[type].type == ELFNOTE_NAME ) + { + elf_msg(elf, "ELF: note: %s\n", note_desc[type].name); + } parms->elf_notes[type].name = note_desc[type].name; switch ( type ) From patchwork Tue Mar 19 20:58:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13597065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C329AC54E68 for ; Tue, 19 Mar 2024 20:59:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.695612.1085510 (Exim 4.92) (envelope-from ) id 1rmgYB-00009W-QP; Tue, 19 Mar 2024 20:59:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 695612.1085510; Tue, 19 Mar 2024 20:59:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rmgYB-00009O-Mr; Tue, 19 Mar 2024 20:59:11 +0000 Received: by outflank-mailman (input) for mailman id 695612; Tue, 19 Mar 2024 20:59:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rmgY9-0007xt-Vm for xen-devel@lists.xenproject.org; Tue, 19 Mar 2024 20:59:10 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20601.outbound.protection.outlook.com [2a01:111:f403:2412::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 86f97b9e-e633-11ee-afdd-a90da7624cb6; Tue, 19 Mar 2024 21:59:08 +0100 (CET) Received: from CH5P221CA0012.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:1f2::16) by MW4PR12MB6852.namprd12.prod.outlook.com (2603:10b6:303:207::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.30; Tue, 19 Mar 2024 20:59:05 +0000 Received: from CH1PEPF0000A348.namprd04.prod.outlook.com (2603:10b6:610:1f2:cafe::24) by CH5P221CA0012.outlook.office365.com (2603:10b6:610:1f2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.28 via Frontend Transport; Tue, 19 Mar 2024 20:59:05 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000A348.mail.protection.outlook.com (10.167.244.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Tue, 19 Mar 2024 20:59:04 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 19 Mar 2024 15:59:04 -0500 Received: from fedora.mshome.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Tue, 19 Mar 2024 15:59:03 -0500 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: 86f97b9e-e633-11ee-afdd-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O77yB8uUAxJRIwxnzSCmsI7E+mctTib3+e9nx7TzSkspmgBLZnbSKNbUlA8ltngCjpJKfgEZYAznjlpHpPt24cl8DehSLpUP1caV3Y2uD/0ptJ9To9RjgOmsLDC6UqzNSp85nXgzlgnS5/LI1MEYsMDbsgg0OYayFdnUXEk12oJtrenVudhsSyVbYS2Fg0o4DbE8HheVlTIhUfxXWt/R+wpJwLQEwUeV82GxozcIoFuh6wJCMkBHr0EWBm3LVoTplpY806p3zwyKo273xsGj+xBGT3ga3hUaV/ayqjB0jDGo0Zaz367zF1jx+ILCQlLP7p4+GiBMqWcSsywrsXhr3g== 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=ubecenY8h+cFWrLnty23ZPYxaQGRZIUEbcYcQZ6BJcU=; b=fwNLCu87IX6lsjsgTMK2vLsOkB1vWogb3uez3IxhvgM5V4NWz9jaPB2plRGxGCjPLsmcN4F65vsGwsHQGJU2bEC7zzeKnBDcpjcGsuMiJEZpun1WW26zkUMfF8E0d8PwF+vdakmPw+QWpMZcn7fKYlrW3iGTTBdJh/fjC3Sum4VW3rPRYto/wiSZ/sGR76WyrOQ0HaMYnzi0QuTDJ3ndT44ytldNnQ8+6I7RO5M8q2BY/th4dJxnnEdlTSleZa95/HJkIkfC/R6y8WytbJ7CVTiyuNU8Vv7N+rojm+JswQ0HJJONPFY6D0w0NdUGMFCcEqEDtPH2HdC2JpZanbcHjg== 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 (0) 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=ubecenY8h+cFWrLnty23ZPYxaQGRZIUEbcYcQZ6BJcU=; b=B111KHkg3vYZ9uvZP25R9kbpuc48iXiUdcuHGyJnbUVXGkiTPsvq0DuXKvOQf2OoKudolPNDTO0fN50DEDeRVxpmF1OCDUuDUA2J7F0hFdQm4hB2WKuAaMq4Rvt1gwcGFbrmnHRvLYu8LTObBx5+XTZmO436UO0lByIkY68LnFo= 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 (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=SATLEXMB04.amd.com; pr=C From: Jason Andryuk To: CC: Jason Andryuk , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v3 3/3] x86/PVH: Support relocatable dom0 kernels Date: Tue, 19 Mar 2024 16:58:49 -0400 Message-ID: <20240319205849.115884-4-jason.andryuk@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240319205849.115884-1-jason.andryuk@amd.com> References: <20240319205849.115884-1-jason.andryuk@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: jason.andryuk@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A348:EE_|MW4PR12MB6852:EE_ X-MS-Office365-Filtering-Correlation-Id: dcf1f5f3-ff17-4de6-2640-08dc4857698d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bTB/la/v1Wb5p5uWuOAgg5iiJqtoM8bur8zfX/nyB/dtzXqULT4Qp80Crw1IMzm0SOOy31jTOB5IeOaIVdbq4CAky/adZ4HmcjEhigYCsa7Xcy2pAbYYO+KjF+uEN+oy9RWWXp9Nyq09ihAVYRu0mcGsXeIQS0jRKGJZFYO7LFZSCr7mMxYcz4QIVKjMWN6Bu6U/k9pzrmzOor4ihHFNHgDvVFHlOCpWwPGNMQ3gVTHEkBXKxClwDZDT1AH2Pb6/ntRoGSvC5V7Jc3rhw0U/Jhf1ROOzcnjQFFWUmc0l+vGi9fc9vlcue7lBl5eIlRdZQC4Ini8BFunkFu+BthfcEKmwQpF5CxmzMrbjNSqlp4I30Dh0maLHpTeyResWqJnyf0+cR+vKIyc+LrU08m4h6MCXU+en51080KspyMp9KKaDaWP0G84ng7N1tl79I/lSlND9BfmIS5u0+nyuuWo8kFJoTHS49KFIM4WElVSz6v7kKrQ3Y20bOSxcPh4+Vq36efKIU2BQbDMEuBkTLW/aVISk6+sQoD93sfFt4KSq9yAr0p/CpIl+lIeBjEJpVZAmYDizHDJB87EgdGCf0jrjSfuHq4u1+7gNTnQIH9v6di+HMvyee3sphaeroqRF+vAz2rBSpS4bA2OGVYpuTcXlQ49MAHvm4vwmxGJdkt0In0Tia3RxHlvINojwkl3nA8GuNsZo5uzPV8dKyNwtoEzSOg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(36860700004)(376005)(1800799015)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2024 20:59:04.9355 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dcf1f5f3-ff17-4de6-2640-08dc4857698d 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000A348.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6852 Xen tries to load a PVH dom0 kernel at the fixed guest physical address from the elf headers. For Linux, this defaults to 0x1000000 (16MB), but it can be configured. Unfortunately there exist firmwares that have reserved regions at this address, so Xen fails to load the dom0 kernel since it's not RAM. The PVH entry code is not relocatable - it loads from absolute addresses, which fail when the kernel is loaded at a different address. With a suitably modified kernel, a reloctable entry point is possible. Add XEN_ELFNOTE_PHYS32_RELOC which specifies optional minimum, maximum and alignment needed for the kernel. The presence of the NOTE indicates the kernel supports a relocatable entry path. Change the loading to check for an acceptable load address. If the kernel is relocatable, support finding an alternate load address. Link: https://gitlab.com/xen-project/xen/-/issues/180 Signed-off-by: Jason Andryuk --- ELF Note printing looks like: (XEN) ELF: note: PHYS32_RELOC = max: 0xffffffff min: 0x1000000 align: 0x200000 v2: Use elfnote for min, max & align - use 64bit values. Print original and relocated memory addresses Use check_and_adjust_load_address() name Return relocated base instead of offset Use PAGE_ALIGN Don't load above max_phys (expected to be 4GB in kernel elf note) Use single line comments Exit check_load_address loop earlier Add __init to find_kernel_memory() v3: Remove kernel_start/end page rounding Change loop comment to rely on a sorted memory map. Reorder E820_RAM check first Use %p for dest_base Use PRIpaddr Use 32bit phys_min/max/align Consolidate to if ( x || y ) continue Use max_t Add parms->phys_reloc Use common "%pd kernel: " prefix for messages Re-order phys_entry assignment Print range ends inclusively Remove extra "Unable to load kernel" message s/PVH_RELOCATION/PHYS32_RELOC/ Make PHYS32_RELOC contents optional Use 2MB default alignment Update ELF Note comment Update XEN_ELFNOTE_MAX --- xen/arch/x86/hvm/dom0_build.c | 94 ++++++++++++++++++++++++++++++ xen/common/libelf/libelf-dominfo.c | 33 +++++++++++ xen/include/public/elfnote.h | 18 +++++- xen/include/xen/libelf.h | 4 ++ 4 files changed, 148 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 0ceda4140b..d2686318c3 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -537,6 +537,97 @@ static paddr_t __init find_memory( return INVALID_PADDR; } +static bool __init check_load_address( + const struct domain *d, const struct elf_binary *elf) +{ + paddr_t kernel_start = (paddr_t)elf->dest_base; + paddr_t kernel_end = kernel_start + elf->dest_size; + unsigned int i; + + /* Relies on a sorted memory map. */ + for ( i = 0; i < d->arch.nr_e820; i++ ) + { + paddr_t start = d->arch.e820[i].addr; + paddr_t end = d->arch.e820[i].addr + d->arch.e820[i].size; + + if ( start >= kernel_end ) + return false; + + if ( d->arch.e820[i].type == E820_RAM && + start <= kernel_start && + end >= kernel_end ) + return true; + } + + return false; +} + +/* Find an e820 RAM region that fits the kernel at a suitable alignment. */ +static paddr_t __init find_kernel_memory( + const struct domain *d, struct elf_binary *elf, + const struct elf_dom_parms *parms) +{ + paddr_t kernel_size = elf->dest_size; + unsigned int i; + + for ( i = 0; i < d->arch.nr_e820; i++ ) + { + paddr_t start = d->arch.e820[i].addr; + paddr_t end = d->arch.e820[i].addr + d->arch.e820[i].size; + paddr_t kstart, kend; + + if ( d->arch.e820[i].type != E820_RAM || + d->arch.e820[i].size < kernel_size ) + continue; + + kstart = ROUNDUP(start, parms->phys_align); + kstart = max_t(paddr_t, kstart, parms->phys_min); + kend = kstart + kernel_size; + + if ( kend > parms->phys_max ) + return 0; + + if ( kend <= end ) + return kstart; + } + + return 0; +} + +/* Check the kernel load address, and adjust if necessary and possible. */ +static bool __init check_and_adjust_load_address( + const struct domain *d, struct elf_binary *elf, struct elf_dom_parms *parms) +{ + paddr_t reloc_base; + + if ( check_load_address(d, elf) ) + return true; + + if ( !parms->phys_reloc ) + { + printk("%pd kernel: Address conflict and not relocatable\n", d); + return false; + } + + reloc_base = find_kernel_memory(d, elf, parms); + if ( reloc_base == 0 ) + { + printk("%pd kernel: Failed find a load address\n", d); + return false; + } + + if ( opt_dom0_verbose ) + printk("%pd kernel: Moving [%p, %p] -> [%"PRIpaddr", %"PRIpaddr"]\n", d, + elf->dest_base, elf->dest_base + elf->dest_size - 1, + reloc_base, reloc_base + elf->dest_size - 1); + + parms->phys_entry = reloc_base + + (parms->phys_entry - (paddr_t)elf->dest_base); + elf->dest_base = (char *)reloc_base; + + return true; +} + static int __init pvh_load_kernel(struct domain *d, const module_t *image, unsigned long image_headroom, module_t *initrd, void *image_base, @@ -585,6 +676,9 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, elf.dest_base = (void *)(parms.virt_kstart - parms.virt_base); elf.dest_size = parms.virt_kend - parms.virt_kstart; + if ( !check_and_adjust_load_address(d, &elf, &parms) ) + return -ENOMEM; + elf_set_vcpu(&elf, v); rc = elf_load_binary(&elf); if ( rc < 0 ) diff --git a/xen/common/libelf/libelf-dominfo.c b/xen/common/libelf/libelf-dominfo.c index 405510ead9..7861e79658 100644 --- a/xen/common/libelf/libelf-dominfo.c +++ b/xen/common/libelf/libelf-dominfo.c @@ -105,6 +105,7 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, ELFNOTE_INT, ELFNOTE_STRING, ELFNOTE_NAME, + ELFNOTE_CUSTOM, } type; } note_desc[] = { [XEN_ELFNOTE_ENTRY] = { "ENTRY", ELFNOTE_INT }, @@ -125,6 +126,7 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, [XEN_ELFNOTE_SUSPEND_CANCEL] = { "SUSPEND_CANCEL", ELFNOTE_INT }, [XEN_ELFNOTE_MOD_START_PFN] = { "MOD_START_PFN", ELFNOTE_INT }, [XEN_ELFNOTE_PHYS32_ENTRY] = { "PHYS32_ENTRY", ELFNOTE_INT }, + [XEN_ELFNOTE_PHYS32_RELOC] = { "PHYS32_RELOC", ELFNOTE_CUSTOM }, }; /* *INDENT-ON* */ @@ -132,6 +134,7 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, uint64_t val = 0; unsigned int i; unsigned type = elf_uval(elf, note, type); + unsigned descsz = elf_uval(elf, note, descsz); if ( (type >= sizeof(note_desc) / sizeof(note_desc[0])) || (note_desc[type].name == NULL) ) @@ -161,6 +164,10 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, { elf_msg(elf, "ELF: note: %s\n", note_desc[type].name); } + else if ( note_desc[type].type == ELFNOTE_CUSTOM ) + { + elf_msg(elf, "ELF: note: %s", note_desc[type].name); + } parms->elf_notes[type].name = note_desc[type].name; switch ( type ) @@ -225,6 +232,28 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, case XEN_ELFNOTE_PHYS32_ENTRY: parms->phys_entry = val; break; + + case XEN_ELFNOTE_PHYS32_RELOC: + parms->phys_reloc = true; + + if ( descsz >= 4 ) + { + parms->phys_max = elf_note_numeric_array(elf, note, 4, 0); + elf_msg(elf, " = max: %#"PRIx32, parms->phys_max); + } + if ( descsz >= 8 ) + { + parms->phys_min = elf_note_numeric_array(elf, note, 4, 1); + elf_msg(elf, " min: %#"PRIx32, parms->phys_min); + } + if ( descsz >= 12 ) + { + parms->phys_align = elf_note_numeric_array(elf, note, 4, 2); + elf_msg(elf, " align: %#"PRIx32, parms->phys_align); + } + + elf_msg(elf, "\n"); + break; } return 0; } @@ -536,6 +565,10 @@ elf_errorstatus elf_xen_parse(struct elf_binary *elf, parms->p2m_base = UNSET_ADDR; parms->elf_paddr_offset = UNSET_ADDR; parms->phys_entry = UNSET_ADDR32; + parms->phys_min = 0; + parms->phys_max = 0xffffffff; + parms->phys_align = 0x200000; + parms->phys_reloc = false; /* Find and parse elf notes. */ count = elf_phdr_count(elf); diff --git a/xen/include/public/elfnote.h b/xen/include/public/elfnote.h index 8bf54d035b..54362b907f 100644 --- a/xen/include/public/elfnote.h +++ b/xen/include/public/elfnote.h @@ -194,10 +194,26 @@ */ #define XEN_ELFNOTE_PHYS32_ENTRY 18 +/* + * Physical loading constraints for PVH kernels + * + * Used to place constraints on the guest physical loading addresses and + * alignment for a PVH kernel. + * + * The presence of this note indicates the kernel supports relocating itself. + * + * The note may include up to three 32bit values in the following order: + * - a maximum address for the entire image to be loaded below (default + * 0xffffffff) + * - a minimum address for the start of the image (default 0) + * - a required start alignment (default 0x200000) + */ +#define XEN_ELFNOTE_PHYS32_RELOC 19 + /* * The number of the highest elfnote defined. */ -#define XEN_ELFNOTE_MAX XEN_ELFNOTE_PHYS32_ENTRY +#define XEN_ELFNOTE_MAX XEN_ELFNOTE_PHYS32_RELOC /* * System information exported through crash notes. diff --git a/xen/include/xen/libelf.h b/xen/include/xen/libelf.h index 1c77e3df31..777c5008ca 100644 --- a/xen/include/xen/libelf.h +++ b/xen/include/xen/libelf.h @@ -434,10 +434,14 @@ struct elf_dom_parms { uint32_t f_supported[XENFEAT_NR_SUBMAPS]; uint32_t f_required[XENFEAT_NR_SUBMAPS]; uint32_t phys_entry; + uint32_t phys_min; + uint32_t phys_max; + uint32_t phys_align; /* calculated */ uint64_t virt_kstart; uint64_t virt_kend; + bool phys_reloc; }; static inline void elf_xen_feature_set(int nr, uint32_t * addr)