From patchwork Wed Mar 27 21:50:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13607534 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 62BEBC54E67 for ; Wed, 27 Mar 2024 21:55:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.698731.1090781 (Exim 4.92) (envelope-from ) id 1rpbEk-0001rw-R2; Wed, 27 Mar 2024 21:55:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 698731.1090781; Wed, 27 Mar 2024 21:55:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpbEk-0001rp-Nd; Wed, 27 Mar 2024 21:55:10 +0000 Received: by outflank-mailman (input) for mailman id 698731; Wed, 27 Mar 2024 21:55:09 +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 1rpbEj-0001dR-BF for xen-devel@lists.xenproject.org; Wed, 27 Mar 2024 21:55:09 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20600.outbound.protection.outlook.com [2a01:111:f403:2418::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ad0e9d23-ec84-11ee-afe3-a90da7624cb6; Wed, 27 Mar 2024 22:55:08 +0100 (CET) Received: from CH2PR08CA0015.namprd08.prod.outlook.com (2603:10b6:610:5a::25) by CH3PR12MB9396.namprd12.prod.outlook.com (2603:10b6:610:1d0::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Wed, 27 Mar 2024 21:55:06 +0000 Received: from CY4PEPF0000EE32.namprd05.prod.outlook.com (2603:10b6:610:5a:cafe::20) by CH2PR08CA0015.outlook.office365.com (2603:10b6:610:5a::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Wed, 27 Mar 2024 21:55:06 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE32.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Wed, 27 Mar 2024 21:55:05 +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.2507.35; Wed, 27 Mar 2024 16:55:04 -0500 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.2507.35; Wed, 27 Mar 2024 16:55: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; Wed, 27 Mar 2024 16:55:04 -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: ad0e9d23-ec84-11ee-afe3-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GdbN+KDAMkJ62GBrKvkgdKlRnwmIuPg5t6b7rvE1ZshHB+eT4JeBBzUvnO22XAwKzdHGvAmK84YSr6jJJeaMh7W8NOtqYRp1hili94v6QRGfwSYV/L8p7LoZ4n1bPhQC6ERaXjVZNw2EVpD1toKWhfLRWOjemz1vCA0D4XeMabHQX9yuZYlileEkXcg0HuaO0JQNWq/m88zeTjRCHfliifXMNItjkyufli/6+5SyWB+CZX60QhNwDfpllcFiuFZyDYc0OURcIyhzvU6ubZutQN0eJWfA5t6WKtYm8TP3pcYoVZEg7+i/gIhlFByDtLo7d55WdeaZluAW/9j+FlWwRA== 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=kpYFdzJHkuO60SpR1aTtd436m2Cbip6KFJuG8vrlzio=; b=GtivoUZaizOp9bN0wYp/dsUIY+aoL5Mj17cirV9DXVWkIkJj82qTxrs7to7VLN+EE8P8HP3W5tQpcnmQ5Qm6LMePx+S0dokTJgLuG1TL3EfMdi8bsHCuyzgLoXjvNDR+wrU5oZmRfXgCmkPsxbW0TnIxbGTgj8uFFLZpyh1DlxY49HJ8Rmrb6huNupAYcgUHeljZG97MXmeWu1O4jsrZjo7cq4s1jMBGLTqwsFMjutFIKWdybP0T6FJaRyfguCVgmhLbrmtfmVbekQYyJ2aP3cdM10LEJl7LDUdv6/oyqY9PEHMeRbY21A4v8tY+vk7xAXTixVdaMUoa4+0ACdQXIg== 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=kpYFdzJHkuO60SpR1aTtd436m2Cbip6KFJuG8vrlzio=; b=4rEtW7lutcfQd4P9DP0d/vWgzEnQjcD6Qa+SvNpcLbCOFTFgY54dbLC7OY7GOXOx4hPlQA7dEbi3+SPo02NmUkMgerl9c/TAk4SO07APOnoa7mikLhfs+ksnuh58i61Yp5cRI1eajw9q1cq9U23UyrD2bpkoBus+SiNfpqtuLiE= 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 , Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v6 1/4] tools/init-xenstore-domain: Replace variable MB() usage Date: Wed, 27 Mar 2024 17:50:59 -0400 Message-ID: <20240327215102.136001-2-jason.andryuk@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327215102.136001-1-jason.andryuk@amd.com> References: <20240327215102.136001-1-jason.andryuk@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: jason.andryuk@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE32:EE_|CH3PR12MB9396:EE_ X-MS-Office365-Filtering-Correlation-Id: a2a330a1-2b12-4784-95a8-08dc4ea88fe8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: acln6GSUv5TKr2UKAaiFuuljqix3fHDWx+AqVZfdKR6t2R20mSPfCaYEw5m1C7LoIpauVh/CYpKGb0JibrmV4EKzN8bODdvn+AKVLK6zJvhxoPEUNFc3p3oK1XtbSp/eyy0HPt9+4cm2cxw9aoElPzHeMe8+6rc5cf6gCWPyOZtyMUfRFxIAy3fI4iYrj6o5p3/y+V+QynA1JRi5n/nKrr2hpMfVOBqU/Iw+5lsfI899Ax5Jqa9Dsdj5IilS9Lk51bcBrWeCzeAVbp+9efPzMjRcVDv4D9hrxkjwkVYyciOJJHCEWMwXIRlzCZTkP14bb3MaCR2glAjv0E9c9G4XHmT9po0K9KMF++mgnvRXjnn67Ygj4iHeA+WTZ9sfCo0RtwdjC8rjnje7Dqx0kZY/2z7FH7n79wIekSmf+57FGkPqT6OtCK2mx5LpIo0S9KqMBRe6LNOrb6CxD/dwnfCTodKy1xOArFcP4I3/U7zP1pIRZbw+N8+shxHwl2qk1nVCVlMJRk/RvL9qAxL8RPYJl3FcKoLtf572yDNVZVo5tr1pJHQl/i2H3pANxLhvk0m7tXpqInPqDk18zGYo95wT1+Xefo7YTGbQEHCk0vMOo5G/xUqFaFD5QWDM8eUTdnzJv5j/nMbcpHFBuLcZCUATfkDlq2IxSdWB/LKdMpcudPx2ECUKpqYYpIZJPuklA0F39OXJ8ZG1utdbOBuceA/zZHoDFiaqW5Y0crNO4WnKn4HFwCjzHSzGPm0g0kWd9pb3 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)(82310400014)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2024 21:55:05.4685 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a2a330a1-2b12-4784-95a8-08dc4ea88fe8 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: CY4PEPF0000EE32.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9396 The local MB() & GB() macros will be replaced with a common implementation, but those only work with constant values. Introduce a static inline mb_to_bytes() in place of the MB() macro to convert the variable values. Signed-off-by: Jason Andryuk Reviewed-by: Anthony PERARD --- v4: New --- tools/helpers/init-xenstore-domain.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c index 1683438c5c..5405842dfe 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -20,7 +20,6 @@ #include "init-dom-json.h" #define LAPIC_BASE_ADDRESS 0xfee00000UL -#define MB(x) ((uint64_t)x << 20) #define GB(x) ((uint64_t)x << 30) static uint32_t domid = ~0; @@ -36,6 +35,11 @@ static xc_evtchn_port_or_error_t console_evtchn; static xentoollog_level minmsglevel = XTL_PROGRESS; static void *logger; +static inline uint64_t mb_to_bytes(int mem) +{ + return (uint64_t)mem << 20; +} + static struct option options[] = { { "kernel", 1, NULL, 'k' }, { "memory", 1, NULL, 'm' }, @@ -76,8 +80,8 @@ static int build(xc_interface *xch) int rv, xs_fd; struct xc_dom_image *dom = NULL; int limit_kb = (maxmem ? : memory) * 1024 + X86_HVM_NR_SPECIAL_PAGES * 4; - uint64_t mem_size = MB(memory); - uint64_t max_size = MB(maxmem ? : memory); + uint64_t mem_size = mb_to_bytes(memory); + uint64_t max_size = mb_to_bytes(maxmem ? : memory); struct e820entry e820[3]; struct xen_domctl_createdomain config = { .ssidref = SECINITSID_DOMU, From patchwork Wed Mar 27 21:51:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13607537 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 4132BCD11DD for ; Wed, 27 Mar 2024 21:55:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.698732.1090790 (Exim 4.92) (envelope-from ) id 1rpbEo-000273-1v; Wed, 27 Mar 2024 21:55:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 698732.1090790; Wed, 27 Mar 2024 21:55:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpbEn-00026w-VJ; Wed, 27 Mar 2024 21:55:13 +0000 Received: by outflank-mailman (input) for mailman id 698732; Wed, 27 Mar 2024 21:55:11 +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 1rpbEl-0001dR-Sy for xen-devel@lists.xenproject.org; Wed, 27 Mar 2024 21:55:11 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20601.outbound.protection.outlook.com [2a01:111:f403:2415::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ae74426e-ec84-11ee-afe3-a90da7624cb6; Wed, 27 Mar 2024 22:55:11 +0100 (CET) Received: from BN8PR07CA0030.namprd07.prod.outlook.com (2603:10b6:408:ac::43) by PH0PR12MB7791.namprd12.prod.outlook.com (2603:10b6:510:280::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Wed, 27 Mar 2024 21:55:08 +0000 Received: from BN2PEPF000044A9.namprd04.prod.outlook.com (2603:10b6:408:ac:cafe::88) by BN8PR07CA0030.outlook.office365.com (2603:10b6:408:ac::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Wed, 27 Mar 2024 21:55:08 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF000044A9.mail.protection.outlook.com (10.167.243.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Wed, 27 Mar 2024 21:55:07 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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; Wed, 27 Mar 2024 16:55:07 -0500 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.2507.35; Wed, 27 Mar 2024 16:55:06 -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; Wed, 27 Mar 2024 16:55:06 -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: ae74426e-ec84-11ee-afe3-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bFrIqIwHnw4I1Jzv5wnCufSzxVPZesBIyEengZO1opcNOZCSmIlcpm9Uk/1zTXlwwrmDY+K2kA4EOl2SaoEGmOW8Cytd6XKhIThVav2DYQ6vdnQLa2Uq+kerU8k8uWv4KjxH8RHCUjw//zcZL/qaj2D/1TpTABFpit28ZmBHdo3yEf0jiwGupeg23uRYR+Xm8xBeOIpHks3/2MymiUd9Nt0eKYd/Tv056Cif4XxR01QlNYrPRdMKK96hAtLIksyp1cTU2rnQidaJFrcH3LhaqWJRpwRe5vxnC+W9Vtxf48fGwp+BjTXyCEWP+FWKRFjJZ0PNB8FDiYlXvUg56iy2uQ== 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=sQPi9MnxIxYvNcw+aMSnS9BZzf8Q8kjV58jecRQgAtM=; b=F5YVg+HqXT3k+/iOOEqixe7IM1zw8/wy67AAzdDK5c/7oRWTXRl3+LfnqK86PRb6Xagg21oMGG/0A7+XoMhH4WjMSgPRx0u7/5eLZQ+CD7WKlZSZGLMt8PJxVIoD3rsbibQHtg00xYc8G7wDCvzSyX0VLF06WltKeKA2FV/5KzJWunCI8pgn8BaI7icMjhyDChI3UOpOnrQYYkSa0XtpZ3BjpJesEuBHqYg2h5NZ8LOAhbGrKuAeTp3qAwiknskYcaRZSQfkLZiv3ZhafBydMrGu4Ihpryla2UbieIIhpRRekfpMPHJ45o1879Z4hVwQkKtHiVcSQVPxzUrjgKGshA== 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=sQPi9MnxIxYvNcw+aMSnS9BZzf8Q8kjV58jecRQgAtM=; b=c0g7Xpa/ddR7UySF4vR/WTVzHo/5ZwcARZ0MEtPI1hTLCzJBDtuAPqSFicd1e6KHjiFW+meqZ57wBG60odKIjVXoMl9mi2k81UhmJaM8GVM1iDjvv97n8EqTn2bCUS6BcPgD0enuomaqRa1Sh2r+TVBEoxhuOj0qImnVLcqJmHs= 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?= , Anthony PERARD , Juergen Gross , Julien Grall Subject: [PATCH v6 2/4] tools: Move MB/GB() to common-macros.h Date: Wed, 27 Mar 2024 17:51:00 -0400 Message-ID: <20240327215102.136001-3-jason.andryuk@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327215102.136001-1-jason.andryuk@amd.com> References: <20240327215102.136001-1-jason.andryuk@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: jason.andryuk@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A9:EE_|PH0PR12MB7791:EE_ X-MS-Office365-Filtering-Correlation-Id: 1901e956-6295-45c7-4cfc-08dc4ea8912b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fVZm54szbFsZFEy+YWu/FNh5ByW1/E4WofAMqJ6e+ZtC3cocYazz/jqOtghItB9+BGorSGKPCbNpgwBVjFmXChZDjk+FXuplHrax2qO476ZX+3oCYd57qRg7xZ0uc8EHK1MtEfjK3IkOa5g9VxtJVNs6ybGDLR3E+kMG4I4bHC9pdkUIe9gIe316IId6NawTXUPRyppvwX/VqzW4Y+Jh2pwTtHB8OT4E5WDBH14Rt/lZLXwEADBeUwQGUdx8uNCB6vv8xUBtENsw5ZdN1orpN+l/e57NY6CsNYUsGJDSN7unxbaXEqzFarO+9HLNJO3nhhhezZolWQYjQi4fdY20mPRBSUANo0BYbetKZgjyDdruPPNqkb2s82Nq8IJPKjDrrQwlyBcIY7cT1nyooJOAWsC+mw9GmpKmr+O/UWuRyQytgLEkqULmigE68zaWrzklwzgl3gRAYykWkwxEo+FRa09e1PY6eivkthFD24foNBv9woArVBkzYXVQ0cWIl7nmm4cOLKAQUpXk38m9epPedYlNa1SbLnXPIcYZp9lIR1tWZJKmdqmpjS7jFVDHI59Km0p1v6j0u+V1UoZws+yEnFbhT5qeFiM8EPxc17nah/rVDSazcmrys828dmts80/gexumPRVpp25l+LTYURW+xzu29ZcPPSpxDlVVFHGxZd8eKo0jAw9eu4jsV/2ffSn3oVp28idrlUhPFAFX1Nk40rtoBms6zhSAmw3c+7sPDAW6HeDMogWG/CitkR0NBTLV 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)(1800799015)(376005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2024 21:55:07.6305 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1901e956-6295-45c7-4cfc-08dc4ea8912b 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: BN2PEPF000044A9.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7791 Consolidate to a single set of common macros for tools. MB() will gain another use in libelf, so this movement makes it available. Requested-by: Jan Beulich Signed-off-by: Jason Andryuk Reviewed-by: Jan Beulich Acked-by: Anthony PERARD --- v4: New v5: Add Jan's R-b & Req-b --- tools/firmware/hvmloader/util.h | 3 --- tools/helpers/init-xenstore-domain.c | 1 - tools/include/xen-tools/common-macros.h | 4 ++++ tools/libs/light/libxl_internal.h | 4 ---- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h index 87be213dec..14078bde1e 100644 --- a/tools/firmware/hvmloader/util.h +++ b/tools/firmware/hvmloader/util.h @@ -38,9 +38,6 @@ void __bug(const char *file, int line) __attribute__((noreturn)); #define BUG() __bug(__FILE__, __LINE__) #define BUG_ON(p) do { if (p) BUG(); } while (0) -#define MB(mb) (mb##ULL << 20) -#define GB(gb) (gb##ULL << 30) - static inline int test_bit(unsigned int b, const void *p) { return !!(((const uint8_t *)p)[b>>3] & (1u<<(b&7))); diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c index 5405842dfe..f38ba8d6b5 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -20,7 +20,6 @@ #include "init-dom-json.h" #define LAPIC_BASE_ADDRESS 0xfee00000UL -#define GB(x) ((uint64_t)x << 30) static uint32_t domid = ~0; static char *kernel; diff --git a/tools/include/xen-tools/common-macros.h b/tools/include/xen-tools/common-macros.h index 81fba2e9f5..07aed92684 100644 --- a/tools/include/xen-tools/common-macros.h +++ b/tools/include/xen-tools/common-macros.h @@ -91,6 +91,10 @@ #define __AC(X, Y) (X ## Y) #define _AC(X, Y) __AC(X, Y) +/* Size macros. */ +#define MB(_mb) (_AC(_mb, ULL) << 20) +#define GB(_gb) (_AC(_gb, ULL) << 30) + #define get_unaligned_t(type, ptr) ({ \ const struct { type x; } __packed *ptr_ = (typeof(ptr_))(ptr); \ ptr_->x; \ diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h index 094d0df9b1..803dbc1a03 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -126,10 +126,6 @@ #define PVSHIM_BASENAME "xen-shim" #define PVSHIM_CMDLINE "pv-shim console=xen,pv" -/* Size macros. */ -#define MB(_mb) (_AC(_mb, ULL) << 20) -#define GB(_gb) (_AC(_gb, ULL) << 30) - #define DIV_ROUNDUP(n, d) (((n) + (d) - 1) / (d)) #define LIBXL__LOGGING_ENABLED From patchwork Wed Mar 27 21:51:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13607536 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 4A4DECD1287 for ; Wed, 27 Mar 2024 21:55:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.698733.1090801 (Exim 4.92) (envelope-from ) id 1rpbEq-0002NS-BO; Wed, 27 Mar 2024 21:55:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 698733.1090801; Wed, 27 Mar 2024 21:55:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpbEq-0002NK-6x; Wed, 27 Mar 2024 21:55:16 +0000 Received: by outflank-mailman (input) for mailman id 698733; Wed, 27 Mar 2024 21:55:15 +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 1rpbEp-0002MB-F5 for xen-devel@lists.xenproject.org; Wed, 27 Mar 2024 21:55:15 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20600.outbound.protection.outlook.com [2a01:111:f403:2416::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id af94aaf8-ec84-11ee-a1ef-f123f15fe8a2; Wed, 27 Mar 2024 22:55:13 +0100 (CET) Received: from SJ0PR13CA0090.namprd13.prod.outlook.com (2603:10b6:a03:2c4::35) by DM6PR12MB4329.namprd12.prod.outlook.com (2603:10b6:5:211::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Wed, 27 Mar 2024 21:55:09 +0000 Received: from CY4PEPF0000EE37.namprd05.prod.outlook.com (2603:10b6:a03:2c4:cafe::b4) by SJ0PR13CA0090.outlook.office365.com (2603:10b6:a03:2c4::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Wed, 27 Mar 2024 21:55:09 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE37.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Wed, 27 Mar 2024 21:55:08 +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; Wed, 27 Mar 2024 16:55:07 -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; Wed, 27 Mar 2024 16:55:07 -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: af94aaf8-ec84-11ee-a1ef-f123f15fe8a2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i1v4y8zPqYmpoxGgMlvyFZ7LJhvsNfHUFczFIJC7R7kcuaswSl/0pBProEuvBv59pTlqlYNHSOiCOPMazX9iEeKjEHkHLNhAM3m2kFmevr4y4nW4FHAOYm8sNg6u0XNWzgMs9j6DHmWr7zTgtW5M1nd1g4NMj+Mii4Y91QGoU/m5C5ByQ0q/N3BK2POrP2zgi1psljF28roSJeIttlVPeCxItWWTYUcMrvuanwAity422vCkHQZBQOxmMy7utMyQGD8fOADiYPNwzEdxqQy17wdKhrOUb/SwquqJP56WxPjLQAR4+DedXqUC7iwvtySaynevN7Ta8rwM1QbQYYCdjg== 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=NCUNHAud3RKnNZN44YqJ/JNK6UfzaIxSGxEmG+Yk0iE=; b=GKuitne/DQA2GsounsDhcMJyiaXCSth3u/eSivpsUgl1uWDF/BgcvkC5gs61t+vz5P8F17oYojUlo51rSFMKO/cFet4gqOOjps85266L2jzTJ09VZUPA+olC0/IwEEWTJFZSQM3BPHw+MeHJNoPsxHGd8w8nyMPGOSdRdfuRHCpFSChVGrbEg8a/E4hMwtuCqq1Xg3G1PaFKC2Ng6WWOGgnfXxUV+1NBnRwwNWsJPdhyPJWE1WHAQuQPYV03UCLw580hTe85sWVSB2efqVeO47PEEnkBvDISGv+6jxULfRKU2sSLCZ7x21LXw2c+g0Ygt+GB0neUHF+H+ViP7r+zvg== 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=NCUNHAud3RKnNZN44YqJ/JNK6UfzaIxSGxEmG+Yk0iE=; b=P4eKQU41W01UYzvBF5z3aKMTMU63QZbvhdx2b9bnvpvt1q0jdpeUmPcyjSjRXUu5iFThMEz+amrSie508zAttnfZTW/ks+NI6c029HMaZniQA11I8oXAGMW0r+3/W7HSOmfYqDgDxKUXJ+FhaTeRzMjYtVI8taGPehvO/JEI9Fw= 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 , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , "Stefano Stabellini" Subject: [PATCH v6 3/4] libelf: Store maximum PHDR p_align Date: Wed, 27 Mar 2024 17:51:01 -0400 Message-ID: <20240327215102.136001-4-jason.andryuk@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327215102.136001-1-jason.andryuk@amd.com> References: <20240327215102.136001-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: CY4PEPF0000EE37:EE_|DM6PR12MB4329:EE_ X-MS-Office365-Filtering-Correlation-Id: db537cd5-42e1-425e-31b8-08dc4ea891d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A53CxzDskgTzRsYz/UFZ3gpBXN3b7heHERXVv3ADATSbaQTS7SuCt0mdFPPKYdI1C7LpzOmvrquhQ7G+c05NmF4fyxkyJGkk6LHQ84/MZiTVgYDbAIaRpOJp1RD76WXw0nQoMpZ264pzKlEb36Hm3gDu+seN0AP0gEkPAKUxyuhlbp/pxGQxT+oyCiqf+NrdZ8M8TqRzM+FM0l6WIBxT/8UE6wTai71kxkh4Gn7OGhLigPiSymBt0jiphiIHVak0BSHLKXCsDo/pCM2g0rKN+APW+fvBlPi8KvcbCd/VGRcSk4PjABLFlzzsTJECaOFdcY6DYsQT3GICTX99n3kuH3r7Sl5AGEdMeYDh1WnSj43pw9hiHdI0uXuIiZE50WVUAo/vX+FoOvZRmWItHlD3glxyLdWnP1FFyUg99Uwtpx3evYCHkSUueadUdfzR0HFpfzUFE+0LUm81h+MFjBMTJnoBA0/vpOmXrxvDF9NZRC4ZdzrBXdV1maY9pAeYYqBaPKRwObEOlZ/BthIONxW5uyMd75QQWz83Qgst72a33uztntckX4C89LCiuDT9RrSllCVaMDFt9lNKc2WuMmPSanW+gTzhmtVgHMUWqW+Hw6eEPx39tKmdU4Z425zQSs5Z3CuX0IaTec10osPv5Lm1O3k5GOnF8CrL52ghkETigUhuvbWlFh9jfD6AeLO57mXqrv7e3blhtWGXjohMYXEliVHIakiB+GJrLYcKWSuIJzk11bUcYpV7/d6Uo9HFN+Y7 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)(1800799015)(82310400014)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2024 21:55:08.6380 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: db537cd5-42e1-425e-31b8-08dc4ea891d7 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: CY4PEPF0000EE37.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4329 While parsing the PHDRs, store the maximum p_align value. This may be consulted for moving a PVH image's load address. Signed-off-by: Jason Andryuk --- v6: New --- xen/common/libelf/libelf-loader.c | 15 +++++++++++---- xen/include/xen/libelf.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/xen/common/libelf/libelf-loader.c b/xen/common/libelf/libelf-loader.c index 629cc0d3e6..a5f6389f82 100644 --- a/xen/common/libelf/libelf-loader.c +++ b/xen/common/libelf/libelf-loader.c @@ -468,6 +468,7 @@ void elf_parse_binary(struct elf_binary *elf) { ELF_HANDLE_DECL(elf_phdr) phdr; uint64_t low = -1, high = 0, paddr, memsz; + uint64_t max_align = 0, palign; unsigned i, count; count = elf_phdr_count(elf); @@ -481,17 +482,23 @@ void elf_parse_binary(struct elf_binary *elf) continue; paddr = elf_uval(elf, phdr, p_paddr); memsz = elf_uval(elf, phdr, p_memsz); - elf_msg(elf, "ELF: phdr: paddr=%#" PRIx64 " memsz=%#" PRIx64 "\n", - paddr, memsz); + palign = elf_uval(elf, phdr, p_align); + elf_msg(elf, + "ELF: phdr: paddr=%#" PRIx64 " memsz=%#" PRIx64 " palign=%#" PRIx64 "\n", + paddr, memsz, palign); if ( low > paddr ) low = paddr; if ( high < paddr + memsz ) high = paddr + memsz; + if ( max_align < palign ) + max_align = palign; } elf->pstart = low; elf->pend = high; - elf_msg(elf, "ELF: memory: %#" PRIx64 " -> %#" PRIx64 "\n", - elf->pstart, elf->pend); + elf->palign = max_align; + elf_msg(elf, + "ELF: memory: %#" PRIx64 " -> %#" PRIx64 " align:%#" PRIx64 "\n", + elf->pstart, elf->pend, elf->palign); } elf_errorstatus elf_load_binary(struct elf_binary *elf) diff --git a/xen/include/xen/libelf.h b/xen/include/xen/libelf.h index 1c77e3df31..2d971f958e 100644 --- a/xen/include/xen/libelf.h +++ b/xen/include/xen/libelf.h @@ -196,6 +196,7 @@ struct elf_binary { size_t dest_size; uint64_t pstart; uint64_t pend; + uint64_t palign; uint64_t reloc_offset; uint64_t bsd_symtab_pstart; From patchwork Wed Mar 27 21:51:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13607538 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 DA5F5C47DD9 for ; Wed, 27 Mar 2024 21:55:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.698734.1090811 (Exim 4.92) (envelope-from ) id 1rpbEv-0002jN-LT; Wed, 27 Mar 2024 21:55:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 698734.1090811; Wed, 27 Mar 2024 21:55:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpbEv-0002j8-IW; Wed, 27 Mar 2024 21:55:21 +0000 Received: by outflank-mailman (input) for mailman id 698734; Wed, 27 Mar 2024 21:55:20 +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 1rpbEu-0002MB-5P for xen-devel@lists.xenproject.org; Wed, 27 Mar 2024 21:55:20 +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 b25f16bf-ec84-11ee-a1ef-f123f15fe8a2; Wed, 27 Mar 2024 22:55:18 +0100 (CET) Received: from SA9PR13CA0137.namprd13.prod.outlook.com (2603:10b6:806:27::22) by DM4PR12MB6374.namprd12.prod.outlook.com (2603:10b6:8:a3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.24; Wed, 27 Mar 2024 21:55:13 +0000 Received: from SA2PEPF000015CD.namprd03.prod.outlook.com (2603:10b6:806:27:cafe::b8) by SA9PR13CA0137.outlook.office365.com (2603:10b6:806:27::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Wed, 27 Mar 2024 21:55:13 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SA2PEPF000015CD.mail.protection.outlook.com (10.167.241.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Wed, 27 Mar 2024 21:55:12 +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.2507.35; Wed, 27 Mar 2024 16:55:09 -0500 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.2507.35; Wed, 27 Mar 2024 16:55:08 -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; Wed, 27 Mar 2024 16:55:07 -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: b25f16bf-ec84-11ee-a1ef-f123f15fe8a2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KBbCMWxeRRXGV8ZKEvgZeg7QOYPpX9a15aLN8jN95geBNAJVcV4Gqyligb7c5IsP2oGUba1Bh1uYktvULwd/QYpM+Xv/HvCrxLg/rIQ/GgYvO3yRrJVCTqQLdor+eY7TxRSgUJlwqP98DrPwmCY+nQGEXkz4QKlc4/ut29E4sBnghG+D+M+O0duRDpcucVoIJxlG9Uqc/2WLkbmwBOicoYQwhjd35YKKVWC6YQqXVIOFfrAR5BXvyZhKh4rDU/Ckj4cZh7qsXG92CrXGoatPf7nohNolmIBMgSzVtzU7pJDCv2Ex9feVQX8YCbxteVQwjZnfUuPrMIuJWyKJq9V/eA== 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=QjKlJSg9cT/vFlsYwh8UTOiO/XXv5HOBwoiNoPGXXHs=; b=TE3+CQVWuxwMqZQHH7TS2vU9zrb7/p+UVvIgZV8V0oXdk1Umn17c2A2j5edNTqJav7sgQOASnLYRXVpo4CWeuehI3RzYNA0mRa/BBOPz4zfvipGWFleTDnNvrtrsKuQM3bNk7oexOVs1O6BCza/vP9K0HyhCLMotty1V1c3IY3+G26pQ/gogrF0YIv7jBDrkxjWxfvdOlfq+dOvL0AiLbW+tcxlB3AGFiGFPkTPLF1daursQ0LO1CTW9LYo9AFYnvb8D1f6LS2qU45I4Uo2TdvlhlPRY6LWtx9H43dsrZr2Nf6CjMIUQynTaiOsSN3zE/RFj+KE4MvafmD6PK/ySGQ== 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=QjKlJSg9cT/vFlsYwh8UTOiO/XXv5HOBwoiNoPGXXHs=; b=pHitPNXv/yzRAXIHK42gbMeSAQZ7NSvfsltQ7Ic6X/K5ZDw7wcfQdCxZNc7KCJohr8p5Rh3M9HQ9wk9ovrUy5oZxvRigypTfselUZ78ef+3fgvSiBw/tg9VRxhfXijxKgcF2M0EHQOc3at6hQQq8MEySdyfdCEK0J4fOM4+Uo5Y= 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?= , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v6 4/4] x86/PVH: Support relocatable dom0 kernels Date: Wed, 27 Mar 2024 17:51:02 -0400 Message-ID: <20240327215102.136001-5-jason.andryuk@amd.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327215102.136001-1-jason.andryuk@amd.com> References: <20240327215102.136001-1-jason.andryuk@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: jason.andryuk@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CD:EE_|DM4PR12MB6374:EE_ X-MS-Office365-Filtering-Correlation-Id: 954a892c-737b-4c0c-99e0-08dc4ea8941d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EUd2vsDMTegDgLCUkY1YpnRGamNu3O0oUC2xGITCWvZVw/mhOB77/1vauVvCuipQSVyH7ndRT4z0y2gfrZGHePA9HPGEhfs0vRZ9vB8VvVo8evi1efrp+8uL66N5s1pnZoUaUeozejZ5LCW9SVdatJy0KvD7Veisl9qFuIHPJ9Z+W0tzZBS9AEiIlTX6rDStZPCU9ZLdGjlwzeewUtvb+ie2XDeypiC7GQdLfAF58BevisoqbRShHIopZvLNqSsJksgldPIclyFUyGep01sfjInxAd+lF7h0G1po3mxy2KhQqyrpjOFN0VSuINgbwKYhgqJ/XHguj/xH+gQJw7Bklk6qssfmuHih6WHC4kNGAyK8CFcN2LTOE0lkf1ZFxraOEBbUZYXb1AmwZqgtvVEDReZeuyQCpHNn7Tv7SNYITNV4uDwyRzmm8ukAM2oxwsitaSLwmULxUMpkPlObOWe4njUxg1mNhqljTrSB6ycXba6Lqj7E3jv07aKmDWQvLWc8DCiN5xYA3ndq0bR9kbm94aKc18bEO4dIvbyN9G+2fGIgrMaAY5wrkENJOZHMkpxCgCskQ2N5SSZXqS2xrHLyFazAJMj18cUUXfb+RCaz374J5lJ3ah8dPM6dgEolRtFIHaCUR+lpEMSv34fhWMln06IMDUXbMPA4mO41jwZuj5YberT3iaoGVQlCFgLJ47jI9h/WealIaMNG1MvB0VLFBbH4Wk5C03Dt+u2lG/uPDgvifbkTamgscS/L7GJe1DHO 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)(1800799015)(376005)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2024 21:55:12.5582 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 954a892c-737b-4c0c-99e0-08dc4ea8941d 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: SA2PEPF000015CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6374 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 alignment, minimum, and maximum addresses 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. The primary motivation for an explicit align field is that Linux has a configurable CONFIG_PHYSICAL_ALIGN field. This value is present in the bzImage setup header, but not the ELF program headers p_align, which report 2MB even when CONFIG_PHYSICAL_ALIGN is greater. Since a kernel is only considered relocatable if the PHYS32_RELOC elf note is present, the alignment contraints can just be specified within the note instead of searching for an alignment value via a heuristic. Load alignment uses the PHYS32_RELOC note value if specified. Otherwise, the maxmum ELF PHDR p_align value is selected if greater than or equal to PAGE_SIZE. Finally, the fallback default is 2MB. libelf-private.h includes common-macros.h to satisfy the fuzzer build. Link: https://gitlab.com/xen-project/xen/-/issues/180 Signed-off-by: Jason Andryuk --- ELF Note printing looks like: (XEN) ELF: note: PHYS32_RELOC align: 0x200000 min: 0x1000000 max: 0x3fffffff 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 v4: Cast dest_base to uintptr_t Use local start variable Mention e820 requiring adjacent entries merged Remove extra whitespace Re-word elfnote comment & mention x86 Use ELFNOTE_NAME Return -ENOSPC Use ! instead of == 0 Check kend - 1 to avoid off by one libelf: Use MB/GB() to define the size. Use ARCH_PHYS_* defines v5: Place kernel in higher memory addresses Remove stray semicolons ELFNOTE_NAME comment about newline Make PHYS32_RELOC element order align, min, max Re-word PHYS32_RELOC comment Move phys_align next to other bool variables v6: Select alignment from, in order, Note, PHDRs, then default --- xen/arch/x86/hvm/dom0_build.c | 108 +++++++++++++++++++++++++++++ xen/common/libelf/libelf-dominfo.c | 35 ++++++++++ xen/common/libelf/libelf-private.h | 1 + xen/include/public/elfnote.h | 16 ++++- xen/include/xen/libelf.h | 4 ++ 5 files changed, 163 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 0ceda4140b..01f39d650e 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -537,6 +537,111 @@ 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 = (uintptr_t)elf->dest_base; + paddr_t kernel_end = kernel_start + elf->dest_size; + unsigned int i; + + /* Relies on a sorted memory map with adjacent entries merged. */ + for ( i = 0; i < d->arch.nr_e820; i++ ) + { + paddr_t start = d->arch.e820[i].addr; + paddr_t end = start + 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 align; + int i; + + if ( parms->phys_align != UNSET_ADDR32 ) + align = parms->phys_align; + else if ( elf->palign > PAGE_SIZE ) + align = elf->palign; + else + align = MB(2); + + /* Search backwards to find the highest address. */ + for ( i = d->arch.nr_e820 - 1; i >= 0 ; i-- ) + { + paddr_t start = d->arch.e820[i].addr; + paddr_t end = start + 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; + + if ( start > parms->phys_max ) + continue; + + if ( end - 1 > parms->phys_max ) + end = parms->phys_max + 1; + + kstart = (end - kernel_size) & ~(align - 1); + kend = kstart + kernel_size; + + if ( kstart < parms->phys_min ) + return 0; + + if ( kstart >= start && 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 ) + { + 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 - (uintptr_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 +690,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 -ENOSPC; + 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 0cdb419b8a..260294d0ed 100644 --- a/xen/common/libelf/libelf-dominfo.c +++ b/xen/common/libelf/libelf-dominfo.c @@ -17,6 +17,14 @@ #include "libelf-private.h" +#if defined(__i386__) || defined(__x86_64__) +#define ARCH_PHYS_MIN_DEFAULT 0 +#define ARCH_PHYS_MAX_DEFAULT (GB(4) - 1) +#else +#define ARCH_PHYS_MIN_DEFAULT 0 +#define ARCH_PHYS_MAX_DEFAULT 0 +#endif + /* ------------------------------------------------------------------------ */ /* xen features */ @@ -125,6 +133,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_NAME }, }; /* *INDENT-ON* */ @@ -132,6 +141,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) ) @@ -228,6 +238,27 @@ 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_align = elf_note_numeric_array(elf, note, 4, 0); + elf_msg(elf, " align: %#"PRIx32, parms->phys_align); + } + 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_max = elf_note_numeric_array(elf, note, 4, 2); + elf_msg(elf, " max: %#"PRIx32, parms->phys_max); + } + + break; } if ( note_desc[type].type == ELFNOTE_NAME) @@ -543,6 +574,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_align = UNSET_ADDR32; + parms->phys_min = ARCH_PHYS_MIN_DEFAULT; + parms->phys_max = ARCH_PHYS_MAX_DEFAULT; + parms->phys_reloc = false; /* Find and parse elf notes. */ count = elf_phdr_count(elf); diff --git a/xen/common/libelf/libelf-private.h b/xen/common/libelf/libelf-private.h index 47db679966..98cac65bc5 100644 --- a/xen/common/libelf/libelf-private.h +++ b/xen/common/libelf/libelf-private.h @@ -71,6 +71,7 @@ #endif #include #include +#include #ifndef FUZZ_NO_LIBXC #include "xenctrl.h" diff --git a/xen/include/public/elfnote.h b/xen/include/public/elfnote.h index 1d84b05f44..a2f89bdc40 100644 --- a/xen/include/public/elfnote.h +++ b/xen/include/public/elfnote.h @@ -196,10 +196,24 @@ */ #define XEN_ELFNOTE_PHYS32_ENTRY 18 +/* + * Physical loading constraints for PVH kernels + * + * The presence of this note indicates the kernel supports relocating itself. + * + * The note may include up to three 32bit values to place constraints on the + * guest physical loading addresses and alignment for a PVH kernel. Values + * are read in the following order: + * - a required start alignment (default 0x200000) + * - a minimum address for the start of the image (default 0) + * - a maximum address for the last byte of the image (default 0xffffffff) + */ +#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 2d971f958e..9ac530acc2 100644 --- a/xen/include/xen/libelf.h +++ b/xen/include/xen/libelf.h @@ -426,6 +426,7 @@ struct elf_dom_parms { enum xen_pae_type pae; bool bsd_symtab; bool unmapped_initrd; + bool phys_reloc; uint64_t virt_base; uint64_t virt_entry; uint64_t virt_hypercall; @@ -435,6 +436,9 @@ 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_align; + uint32_t phys_min; + uint32_t phys_max; /* calculated */ uint64_t virt_kstart;