From patchwork Fri Aug 23 19:36:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13775751 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 46B08C531DC for ; Fri, 23 Aug 2024 19:36:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.782599.1192110 (Exim 4.92) (envelope-from ) id 1sha5W-0002S6-KP; Fri, 23 Aug 2024 19:36:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 782599.1192110; Fri, 23 Aug 2024 19:36:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sha5W-0002RI-EG; Fri, 23 Aug 2024 19:36:46 +0000 Received: by outflank-mailman (input) for mailman id 782599; Fri, 23 Aug 2024 19:36:45 +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 1sha5V-0002Oa-0z for xen-devel@lists.xenproject.org; Fri, 23 Aug 2024 19:36:45 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2060f.outbound.protection.outlook.com [2a01:111:f403:2415::60f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 05721e38-6187-11ef-a50a-bb4a2ccca743; Fri, 23 Aug 2024 21:36:42 +0200 (CEST) Received: from BN9PR03CA0787.namprd03.prod.outlook.com (2603:10b6:408:13f::12) by MW6PR12MB8867.namprd12.prod.outlook.com (2603:10b6:303:249::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Fri, 23 Aug 2024 19:36:37 +0000 Received: from BN2PEPF000044A9.namprd04.prod.outlook.com (2603:10b6:408:13f:cafe::41) by BN9PR03CA0787.outlook.office365.com (2603:10b6:408:13f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.22 via Frontend Transport; Fri, 23 Aug 2024 19:36:37 +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.7897.11 via Frontend Transport; Fri, 23 Aug 2024 19:36:37 +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.39; Fri, 23 Aug 2024 14:36:35 -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.39 via Frontend Transport; Fri, 23 Aug 2024 14:36:33 -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: 05721e38-6187-11ef-a50a-bb4a2ccca743 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=glKcDYjbTAAV9QqRFb3gE29XVc5EUgIBABxXIjd7IKvkId4JZU7pDco/neWOWoJ3DfaJR6ap3LvGcsV7MB7yKWNcQ+e69neisjInrfNqsuEinmkk5xLnSY/SzmdyK58nZVIPr91keS3XWtxtLnDOQMDtNiVZa5SybzqOi1eBFSFNcioPw6G+Tyyg4n74gHRlnoqjpAYIAL+D61v+mTiFhnzPrWdVfc/dEqCgnU8BO8R8PZTTwcKzh9ruDAg+URjXTYYev4w/wqEmVFJLnAGULL8ggnsOuvCV8IvH2AUjlHvDAt4wYrNn0tII93az+OCOGboK5/x5JVsSZdntG1IWjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=55nJnnKdgeDx4oUSXrJ9Q+OVSfhHt48p1gn05H5VmsQ=; b=ipZLfcKjewCf/5hEs5ZX5Qux+kItX4LeWjZiGxnezz4tUmwjMNd3kmj2C+oqOQt7Rzcho6PmLrlXl0qOegxS67wk+CFcc7UZ/pHTnAmEXT8L1i+CMedaJW571BY73IECjPfUGVPBa+126HyTo5mdg51jGjXN8Qi/lwhKEBZtsHn/ca/0yKn9XXtm7sojbMZof/jUL0oAwe3nyj8lYLFzeBdY4A0FNtg9Q4BYxNELRBhBDN/NihMTLl5ZVNQ1jGUQapVklySs3djzPmNNDBR1F+ODIu69xUvdJTHXiqiquL5glAv9I8YubBlqH4y6zkpMqZ6I7AZuXOn1v59ove4rmw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=55nJnnKdgeDx4oUSXrJ9Q+OVSfhHt48p1gn05H5VmsQ=; b=J8yek0kab9gu+QiruPgP5X+JOvunBFxIfZ8KqKBv0rtNILjdlofoXBrNWKihFAVyKj4oo05urZb/49GbhxKhYKWEw1+SriCoNwE8Z7IVtHwIfVPEAJJve3WYIEiUM1GZ0jc8v6KnXXUZKR1D/Er9HtwDux5UnuTm4sPGBaw+TzA= 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: Juergen Gross , Boris Ostrovsky , Thomas Gleixner , "Ingo Molnar" , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" , Stefano Stabellini , "Oleksandr Tyshchenko" , Paolo Bonzini , Brian Gerst CC: , , "Jason Andryuk" Subject: [PATCH v3 1/5] xen: sync elfnote.h from xen tree Date: Fri, 23 Aug 2024 15:36:26 -0400 Message-ID: <20240823193630.2583107-2-jason.andryuk@amd.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823193630.2583107-1-jason.andryuk@amd.com> References: <20240823193630.2583107-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: BN2PEPF000044A9:EE_|MW6PR12MB8867:EE_ X-MS-Office365-Filtering-Correlation-Id: 679b3fdf-9c96-4805-eb13-08dcc3aae788 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: xC/E2UfBxPY0SLN8cFrgafV2rpiMkAcU+reHtKF7Lp2uvJjIHOYf7HlGOjty/hV6VkF9JND8mFtmWU14rMLlhh87FJLi2DCg67DGKsJ5/tEAKkVbiVax4nQgY8dWFJr6WciAuBtB106Wn9Vf5K4tyqYnkMgojasESTY++oMRqYELGHZygfkncfwOiT3Bs3moIweVoDwiRGzs04DPFT9d8hn5QOrs3TBrYKNW9CVR3E6yRVEVsTs+AvFnWTcDs5HDno6wEIhO/2/eVjkM9F4dN9wKhR5+hJwyhbs7umHI6wTz7qJyNu61hD1azova0fX4A4A9zT9VT3yoGtMFVtNq1UpyvhYj9VTlHielQBo5tdyNJD9AiE5v9RqHUG77N8zAFIXzEsyteY1TvAJnxlW6rvriNwupc0Dgsxu+q/Mjv+Xr9kBrE/843bjk+Sa7Uf7Zb499UJAs5J9q11F+55sxBauId39gP6lFQDVWLogr27TEV95druTSSI4ZtvcWXEe+H/6lysscIf5VH9hlq3ToPe1ulPDfh6Rxm5rxyojKwV+eHqB/qrliv7vj5J7uI/hKAh6VYW/dEoP0Y1eh02bSfnwQp2c5E7b9HTVLAn3mvyWTjmt7X+tW7W3Zow8vSoh1SRf6IlQ5lQi4clNTcNEzIEu/Q2CLhNjQmVmYz7P/aGV5RCWygLTDhGqPTD+Mdz6CkMMmEMefqU8keQASfoxRepz9AknUMqpmRSdBhbxgRCT3hc9bmPH36JjBhoi54qI5wh0/jLmXu/UIjN+Mn+1buNlCU0BMkfzmiSofZl26o4pTFULMLgfgPWElArtIGWs/i2XyMtRn8ozYsX85JUQ/4OgcIhd4+0Jm2f8W5GCAYRkaHQKPzicnM2kt6okMClVkFhY1GwU7c2XsMonJ9iJfjVGjimpHz2RkceBIG+vTSjrZOW1MT4Az0U4j152rSyNbICkKFrRlOvgBpwPcuAZx+QNii1l+47Ei1yvq2pEyvQ4ZDU+tWXemQCCv+EZnWyaE8yzUfMreZ1F0wZKb9puhYCeJbJe3ez9qZPFzRv+kJWW2KkpWQhpLwPBg0VDpBsguaaVvm7mtUPvTVgH38Zo6OhXDkyvs6d58/4Cadj8Cr6jYPqiPZXnfd3wtXkiUu0JClc21O2QIE6uVA2Qyt0joUKxd0zyTZNG3adntykm24cC7fZIUbu29wmIHeNntx/ouaVW+EEY9XZuuq8jRSf1LY5qfiGt1eiYdetm0QQJcKSA0uXAk7/7aGCzLSQrCBuzxGOxPaDUNZq2KTzk8ylt32Ds1390jXrGjkLLuEhFoTF2CjAL65TXsiIAjFZrFAO9YMeCK0xHrbfw4J4wBTe0YInKD7mqh60wbFtxcsmJpnsd6Yv39Eam3RQxxxPMVv63p3NyaLCQS5WBJLiymiTl0tHmMhCiajmGZjYj1eW07QFUaOBUp+Nyo2CaKbmA817SRxeBYTL7GGeNVKn2ItAHiCQ== 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:(13230040)(36860700013)(82310400026)(1800799024)(376014)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 19:36:37.5509 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 679b3fdf-9c96-4805-eb13-08dcc3aae788 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: MW6PR12MB8867 Sync Xen's elfnote.h header from xen.git to pull in the XEN_ELFNOTE_PHYS32_RELOC define. xen commit dfc9fab00378 ("x86/PVH: Support relocatable dom0 kernels") This is a copy except for the removal of the emacs editor config at the end of the file. Signed-off-by: Jason Andryuk Reviewed-by: Juergen Gross --- include/xen/interface/elfnote.h | 93 +++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 5 deletions(-) diff --git a/include/xen/interface/elfnote.h b/include/xen/interface/elfnote.h index 38deb1214613..918f47d87d7a 100644 --- a/include/xen/interface/elfnote.h +++ b/include/xen/interface/elfnote.h @@ -11,7 +11,9 @@ #define __XEN_PUBLIC_ELFNOTE_H__ /* - * The notes should live in a SHT_NOTE segment and have "Xen" in the + * `incontents 200 elfnotes ELF notes + * + * The notes should live in a PT_NOTE segment and have "Xen" in the * name field. * * Numeric types are either 4 or 8 bytes depending on the content of @@ -22,6 +24,8 @@ * * String values (for non-legacy) are NULL terminated ASCII, also known * as ASCIZ type. + * + * Xen only uses ELF Notes contained in x86 binaries. */ /* @@ -52,7 +56,7 @@ #define XEN_ELFNOTE_VIRT_BASE 3 /* - * The offset of the ELF paddr field from the acutal required + * The offset of the ELF paddr field from the actual required * pseudo-physical address (numeric). * * This is used to maintain backwards compatibility with older kernels @@ -92,7 +96,12 @@ #define XEN_ELFNOTE_LOADER 8 /* - * The kernel supports PAE (x86/32 only, string = "yes" or "no"). + * The kernel supports PAE (x86/32 only, string = "yes", "no" or + * "bimodal"). + * + * For compatibility with Xen 3.0.3 and earlier the "bimodal" setting + * may be given as "yes,bimodal" which will cause older Xen to treat + * this kernel as PAE. * * LEGACY: PAE (n.b. The legacy interface included a provision to * indicate 'extended-cr3' support allowing L3 page tables to be @@ -149,7 +158,9 @@ * The (non-default) location the initial phys-to-machine map should be * placed at by the hypervisor (Dom0) or the tools (DomU). * The kernel must be prepared for this mapping to be established using - * large pages, despite such otherwise not being available to guests. + * large pages, despite such otherwise not being available to guests. Note + * that these large pages may be misaligned in PFN space (they'll obviously + * be aligned in MFN and virtual address spaces). * The kernel must also be able to handle the page table pages used for * this mapping not being accessible through the initial mapping. * (Only x86-64 supports this at present.) @@ -185,9 +196,81 @@ */ #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; see below) + * - a maximum address for the last byte of the image (default 0xffffffff) + * + * When this note specifies an alignment value, it is used. Otherwise the + * maximum p_align value from loadable ELF Program Headers is used, if it is + * greater than or equal to 4k (0x1000). Otherwise, the default is used. + */ +#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. + * + * The kexec / kdump code will create one XEN_ELFNOTE_CRASH_INFO + * note in case of a system crash. This note will contain various + * information about the system, see xen/include/xen/elfcore.h. + */ +#define XEN_ELFNOTE_CRASH_INFO 0x1000001 + +/* + * System registers exported through crash notes. + * + * The kexec / kdump code will create one XEN_ELFNOTE_CRASH_REGS + * note per cpu in case of a system crash. This note is architecture + * specific and will contain registers not saved in the "CORE" note. + * See xen/include/xen/elfcore.h for more information. + */ +#define XEN_ELFNOTE_CRASH_REGS 0x1000002 + + +/* + * xen dump-core none note. + * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_NONE + * in its dump file to indicate that the file is xen dump-core + * file. This note doesn't have any other information. + * See tools/libxc/xc_core.h for more information. + */ +#define XEN_ELFNOTE_DUMPCORE_NONE 0x2000000 + +/* + * xen dump-core header note. + * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_HEADER + * in its dump file. + * See tools/libxc/xc_core.h for more information. + */ +#define XEN_ELFNOTE_DUMPCORE_HEADER 0x2000001 + +/* + * xen dump-core xen version note. + * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_XEN_VERSION + * in its dump file. It contains the xen version obtained via the + * XENVER hypercall. + * See tools/libxc/xc_core.h for more information. + */ +#define XEN_ELFNOTE_DUMPCORE_XEN_VERSION 0x2000002 + +/* + * xen dump-core format version note. + * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION + * in its dump file. It contains a format version identifier. + * See tools/libxc/xc_core.h for more information. + */ +#define XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION 0x2000003 #endif /* __XEN_PUBLIC_ELFNOTE_H__ */ From patchwork Fri Aug 23 19:36:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13775750 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 62699C5321E for ; Fri, 23 Aug 2024 19:36:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.782601.1192134 (Exim 4.92) (envelope-from ) id 1sha5Z-00036s-7u; Fri, 23 Aug 2024 19:36:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 782601.1192134; Fri, 23 Aug 2024 19:36:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sha5Z-00036c-42; Fri, 23 Aug 2024 19:36:49 +0000 Received: by outflank-mailman (input) for mailman id 782601; Fri, 23 Aug 2024 19:36:47 +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 1sha5X-0002Oa-P4 for xen-devel@lists.xenproject.org; Fri, 23 Aug 2024 19:36:47 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20602.outbound.protection.outlook.com [2a01:111:f403:2418::602]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0886edd0-6187-11ef-a50a-bb4a2ccca743; Fri, 23 Aug 2024 21:36:47 +0200 (CEST) Received: from BN9PR03CA0603.namprd03.prod.outlook.com (2603:10b6:408:106::8) by LV3PR12MB9187.namprd12.prod.outlook.com (2603:10b6:408:194::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.18; Fri, 23 Aug 2024 19:36:41 +0000 Received: from BL02EPF00021F6D.namprd02.prod.outlook.com (2603:10b6:408:106:cafe::59) by BN9PR03CA0603.outlook.office365.com (2603:10b6:408:106::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21 via Frontend Transport; Fri, 23 Aug 2024 19:36:40 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF00021F6D.mail.protection.outlook.com (10.167.249.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7897.11 via Frontend Transport; Fri, 23 Aug 2024 19:36:39 +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.39; Fri, 23 Aug 2024 14:36:37 -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.39 via Frontend Transport; Fri, 23 Aug 2024 14:36:36 -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: 0886edd0-6187-11ef-a50a-bb4a2ccca743 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ec25Fu0KVgOkM4yHYb1LTlK5N9XXSUUFcpstMD10M3FKFcnlqmcJoGuALa0E3v/eSTnF7awDjj5jIixjeFTsT8pzOzURfYRXONuxmfltTCWw2Oc3duUWzrjt+ZGRYNQ1wTGKJv+0yY3hriiKSnrjKZhhwVn2q/nTBzn91QuJk6WUqzywnAHiMg0BopnDILQI1pJ2rJkwd8tlbiWXGRBRk73ntB/stQirYrRhviwXyY9TaytjajansIg7kqwY4V1ujJoWMVH6rFVCSaV9i3FaH+EnlKZV9vZEt0DssaylAsn7Q7OCImwBvjsJFGTc1Y6/cz34fUAZ4Qg1yW82S3sZxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=726QpRcn+lvf4rCuApM2KwRHNgakfInv/OKNIzKT6VQ=; b=pMzY17WE7Z+Q64BVu/+mXTipzfGBqP8LRFacc6Hfw0mwIcCjKARD7m3pFWZgwlWeJKZhdWgyf+CqZTdk175IYi5TFu+wDY59oaSlBH39kMXt5GvA/of4IdVtp1m98frqlxa8XHLqU3QmevR5Ef2wIUUHealFG8wA+Pybsz7nPyFG6CvXddERB9iHN9wd9f4uLG38gZhpiZhJhgIdeb40NXSciPF0lkRycIrmAB15853Bw01F/TJ+az2A3saVEHE3T/pJAzjiCw3c/x6PRVDzbtqF+7FC7s+rSDw9JEExhrO2KgEEihmXoPS700hR+CIJN8TXYzDsQIwE2N1l4eMifg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=726QpRcn+lvf4rCuApM2KwRHNgakfInv/OKNIzKT6VQ=; b=ALsNO2kVBUmJ2vUnwUE1CXvArrfVNOqZFf17Aop7yZKl9HufKx3nohIM3b4HuPkIgIEjTygJfjN5TbyC36tB07e9ftlcFQrbroJj8bNNqNr2pTBb9FXi/8bQmhwYUjljAOnlsphJhV5oWHM2V388aiUMHRpl2N/Uk+JLdDI9+60= 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: Juergen Gross , Boris Ostrovsky , Thomas Gleixner , "Ingo Molnar" , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" , Stefano Stabellini , "Oleksandr Tyshchenko" , Paolo Bonzini , Brian Gerst CC: , , "Jason Andryuk" Subject: [PATCH v3 2/5] x86/pvh: Make PVH entrypoint PIC for x86-64 Date: Fri, 23 Aug 2024 15:36:27 -0400 Message-ID: <20240823193630.2583107-3-jason.andryuk@amd.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823193630.2583107-1-jason.andryuk@amd.com> References: <20240823193630.2583107-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: BL02EPF00021F6D:EE_|LV3PR12MB9187:EE_ X-MS-Office365-Filtering-Correlation-Id: 4f063824-6117-4102-c97d-08dcc3aae8fd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|36860700013|1800799024|82310400026|921020; X-Microsoft-Antispam-Message-Info: 6VL/RPA3wdiowMbkNy1f1F3Kkr5OHmKjey+aP+IGeny5J5dPWadp+Vr7/KbJIU/znlteWzqOaHDKIab35BDhdRMPwiBzLYuo1SsJ10XwnVmMu8rMVmQWwYvn3gqCn9e7dNqoke3SHTGW83XK54PmDzdnCuQrO1MO+mZXMHpizzHT95C1QVnX9p1GzMUNUNZarjwP/dnWEllcDLLsewFf3m7SR2zQzYX9xmgcK9ZmX+47o9Irktf6xvByWe9H8Mf5yBoEzatuJmumaBQICgXC6WvfteL3fGZZVCd0cB+hYLFQIDqNzTQtL/8Q1+nz1r98izAnUxTaGNmzevXolKOQTT7Jz2s45h565vY9awdLQ1r3GX+vpQv+Ylz1ORicQFcrwx/MuuZRMbXdFvpAE9POQ5ZewTL37I4u3HrYvr07j786qyZZ2LU/FjHEOYmcD23Cf/lJyUTT6chXYOkUT6dqyvfQEFIfl5HsvT5EyKDtnDQcCYxQMastdGwGcR1H1d36bz0zuEzCvvH3KSU88L1L8gvifwWnofep+lRZJIkgWLQyNkdjLiw3oOpSrNQ2pf8tlzCzzIQpF8IGs9CSXx1L5/+EDf0mxbktz4xkFd12vvYKlN/EwocNms7bWOjq6Q7JjH8YwswPYe91iTje8Cmehvqk4mDm1nS+LnudxjColk/o1djRd21fwfr3nQrmL6QrzK1KUXWDyu7n72zcYiPLeP3w5TTxxpijhPNaxqkO+vOTkdPgJk2+RpRDbowYwZFAqbP/E+SfX350EagGJUVfWvTqQpBrTx2wTq+/cccUXuG456Wjn4TB22m/3bfs101oLbfio9bbNHYXHoe0EpILEWMKev3dHJXTxJTH+IVrH47kwe4I/KOFt4xXplnAz76NztrJRd9U9UpjeaT6DZvQNYW5anT2bTcPfPxsDE6nB1PSVv0FZ5P3iMsz3LW7l+V11X+oBhOXiP2ih6xiFXct9GSuLowhh5x+nS+XDVgOmp2fRP4z3z4+SPJ5OUWFe9/kn+1ASj7Wjts8Xkfeps81gQ+VpxG1c3TYkgfigcKttKO/HVmS33iAlhM9a0d43qf44GUkVf9uvxgJqQWvOTe5j5Z+Zeextx4Pgg2SXxO1wya+Y6cfMW5lfTFeSeT0P0S3vbKnIBrAg2WeseMuGDmdzoALCnLUA++9K1P/Uidu3sCK24fTVSjOxIAFrRTMWLJ28FqjKhKpp0xG/E5WGG8K2sddUBgUeZ4KmNrdwmqshV1sCuIExXOh22lSAYG4CM5Ho462zy05NxYgdSLXVA2Z7Ln3HX1FivbZh7VbsDnK9/PGKCRfYXgE32/T9zuOqJUO7cfvuYfogtBSPeB+RSsbWDSeND38qExIi5JI/6XXM5Cbol37RDpcrYTl7FkdD4ehqG+d5SOvT5hMDZea3fLy5WCEGRdAIMI8HZRzVmV9miuzt8CFJh7fYY2z0wlXkfspfHjVZVeDbLaeFaJEk16QaQ== 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:(13230040)(376014)(7416014)(36860700013)(1800799024)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 19:36:39.9789 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4f063824-6117-4102-c97d-08dcc3aae8fd 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: BL02EPF00021F6D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9187 The PVH entrypoint is 32bit non-PIC code running the uncompressed vmlinux at its load address CONFIG_PHYSICAL_START - default 0x1000000 (16MB). The kernel is loaded at that physical address inside the VM by the VMM software (Xen/QEMU). When running a Xen PVH Dom0, the host reserved addresses are mapped 1-1 into the PVH container. There exist system firmwares (Coreboot/EDK2) with reserved memory at 16MB. This creates a conflict where the PVH kernel cannot be loaded at that address. Modify the PVH entrypoint to be position-indepedent to allow flexibility in load address. Only the 64bit entry path is converted. A 32bit kernel is not PIC, so calling into other parts of the kernel, like xen_prepare_pvh() and mk_pgtable_32(), don't work properly when relocated. This makes the code PIC, but the page tables need to be updated as well to handle running from the kernel high map. The UNWIND_HINT_END_OF_STACK is to silence: vmlinux.o: warning: objtool: pvh_start_xen+0x7f: unreachable instruction after the lret into 64bit code. Signed-off-by: Jason Andryuk Reviewed-by: Juergen Gross --- v2: Use rip-relative loads in 64bit mode Direct jmp to startup_64 --- arch/x86/platform/pvh/head.S | 46 ++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index f7235ef87bc3..ba4d0eab4436 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -7,6 +7,7 @@ .code32 .text #define _pa(x) ((x) - __START_KERNEL_map) +#define rva(x) ((x) - pvh_start_xen) #include #include @@ -54,7 +55,25 @@ SYM_CODE_START_LOCAL(pvh_start_xen) UNWIND_HINT_END_OF_STACK cld - lgdt (_pa(gdt)) + /* + * See the comment for startup_32 for more details. We need to + * execute a call to get the execution address to be position + * independent, but we don't have a stack. Save and restore the + * magic field of start_info in ebx, and use that as the stack. + */ + mov (%ebx), %eax + leal 4(%ebx), %esp + ANNOTATE_INTRA_FUNCTION_CALL + call 1f +1: popl %ebp + mov %eax, (%ebx) + subl $rva(1b), %ebp + movl $0, %esp + + leal rva(gdt)(%ebp), %eax + leal rva(gdt_start)(%ebp), %ecx + movl %ecx, 2(%eax) + lgdt (%eax) mov $PVH_DS_SEL,%eax mov %eax,%ds @@ -62,14 +81,14 @@ SYM_CODE_START_LOCAL(pvh_start_xen) mov %eax,%ss /* Stash hvm_start_info. */ - mov $_pa(pvh_start_info), %edi + leal rva(pvh_start_info)(%ebp), %edi mov %ebx, %esi - mov _pa(pvh_start_info_sz), %ecx + movl rva(pvh_start_info_sz)(%ebp), %ecx shr $2,%ecx rep movsl - mov $_pa(early_stack_end), %esp + leal rva(early_stack_end)(%ebp), %esp /* Enable PAE mode. */ mov %cr4, %eax @@ -84,30 +103,33 @@ SYM_CODE_START_LOCAL(pvh_start_xen) wrmsr /* Enable pre-constructed page tables. */ - mov $_pa(init_top_pgt), %eax + leal rva(init_top_pgt)(%ebp), %eax mov %eax, %cr3 mov $(X86_CR0_PG | X86_CR0_PE), %eax mov %eax, %cr0 /* Jump to 64-bit mode. */ - ljmp $PVH_CS_SEL, $_pa(1f) + pushl $PVH_CS_SEL + leal rva(1f)(%ebp), %eax + pushl %eax + lretl /* 64-bit entry point. */ .code64 1: + UNWIND_HINT_END_OF_STACK + /* Set base address in stack canary descriptor. */ mov $MSR_GS_BASE,%ecx - mov $_pa(canary), %eax + leal canary(%rip), %eax xor %edx, %edx wrmsr call xen_prepare_pvh /* startup_64 expects boot_params in %rsi. */ - mov $_pa(pvh_bootparams), %rsi - mov $_pa(startup_64), %rax - ANNOTATE_RETPOLINE_SAFE - jmp *%rax + lea pvh_bootparams(%rip), %rsi + jmp startup_64 #else /* CONFIG_X86_64 */ @@ -143,7 +165,7 @@ SYM_CODE_END(pvh_start_xen) .balign 8 SYM_DATA_START_LOCAL(gdt) .word gdt_end - gdt_start - .long _pa(gdt_start) + .long _pa(gdt_start) /* x86-64 will overwrite if relocated. */ .word 0 SYM_DATA_END(gdt) SYM_DATA_START_LOCAL(gdt_start) From patchwork Fri Aug 23 19:36:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13775753 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 C6D70C5321D for ; Fri, 23 Aug 2024 19:36:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.782603.1192150 (Exim 4.92) (envelope-from ) id 1sha5b-0003Qc-3j; Fri, 23 Aug 2024 19:36:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 782603.1192150; Fri, 23 Aug 2024 19:36:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sha5a-0003PP-Q7; Fri, 23 Aug 2024 19:36:50 +0000 Received: by outflank-mailman (input) for mailman id 782603; Fri, 23 Aug 2024 19:36:49 +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 1sha5Z-0002Oa-8V for xen-devel@lists.xenproject.org; Fri, 23 Aug 2024 19:36:49 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060b.outbound.protection.outlook.com [2a01:111:f403:2009::60b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 08e2cd12-6187-11ef-a50a-bb4a2ccca743; Fri, 23 Aug 2024 21:36:48 +0200 (CEST) Received: from BN9PR03CA0612.namprd03.prod.outlook.com (2603:10b6:408:106::17) by PH0PR12MB8128.namprd12.prod.outlook.com (2603:10b6:510:294::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.16; Fri, 23 Aug 2024 19:36:41 +0000 Received: from BL02EPF00021F6D.namprd02.prod.outlook.com (2603:10b6:408:106:cafe::f4) by BN9PR03CA0612.outlook.office365.com (2603:10b6:408:106::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.19 via Frontend Transport; Fri, 23 Aug 2024 19:36:41 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF00021F6D.mail.protection.outlook.com (10.167.249.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7897.11 via Frontend Transport; Fri, 23 Aug 2024 19:36:41 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.39; Fri, 23 Aug 2024 14:36:39 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 23 Aug 2024 14:36:39 -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.39 via Frontend Transport; Fri, 23 Aug 2024 14:36:38 -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: 08e2cd12-6187-11ef-a50a-bb4a2ccca743 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gI4HnmrqD+UJKi1TDmVqqlFkRMKRb5JYcMT5A3AK4fHUyUf/bNwCPOlQOvlmnmOMyzwqtcb9Y3h39ShhlMCDTM5z2AIOWACdsf76L4rqIQCDq9WPGOQQvR18WUnzy41LQhgpd8qQFQh4cS8v5+HVSWXUAISSzlzmWW/W17FeYHTTpzFCDVr/WCq4C74LnFrPTl6S2mpSvVmigvlvjmWQH+3pHE1y0C7iJlybcZAeIwwa42UdZt2AAUDUskBztV3SKaJ8X5ONT5Y5C96hqI2ZWyPIEAzDCdKoP92LnWA4r0r/rUQ2mOczt2eAj/q4dtlCrQneb+ptpWmhWZ7mFtI5qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=87Cir7MUe+90Zd8HQRFVV15Z21B672vcEXroWazgwgg=; b=WRqy621ZsX7veYtjsK9uj3d/oRaukkw3pvP2T6BW/yEX0dlWOG1kaH4qysLPEJW2CIab/ZtdAQE7ZKJIQb77cjfCghavsME8+btwLff2mAFuSVQgnnKmUqwVTmCPHAWX5BrYwhnWX+FaGTvAUNGUokLgiBHCI05MytfgpjSzvUQ07PG7iZ+2NU8thM8YcWIXO3k1Fwvkp0YEebExpJIVutbVIN3z/VQVM5F5ZumNEsuabWnplZKcxpfVNDGSeG17SViWlLBkYYctF1WC44NcTbMilFbjntOd5AucSWXNFFd3EUpdOhf/BFcKwnJG0brjiSHjMM6/EDKCfzombyaa9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=87Cir7MUe+90Zd8HQRFVV15Z21B672vcEXroWazgwgg=; b=OpARkPMAQRESpBjU2iz82I4pyZga0fqaaK3+0M3NlZzDqBSwdMe2G0++Qyq49hE9guqMCGRkzfSB/a0foCcPQYiiweXeui0SAQ9Kg3vcHWPOMHKi9nHD8+IcKa6okYYKWiuh/wxQjuBbaPI87LhKq5I9imGx5/A0mQ+aFzu/IsM= 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: Juergen Gross , Boris Ostrovsky , Thomas Gleixner , "Ingo Molnar" , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" , Stefano Stabellini , "Oleksandr Tyshchenko" , Paolo Bonzini , Brian Gerst CC: , , "Jason Andryuk" Subject: [PATCH v3 3/5] x86/pvh: Set phys_base when calling xen_prepare_pvh() Date: Fri, 23 Aug 2024 15:36:28 -0400 Message-ID: <20240823193630.2583107-4-jason.andryuk@amd.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823193630.2583107-1-jason.andryuk@amd.com> References: <20240823193630.2583107-1-jason.andryuk@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00021F6D:EE_|PH0PR12MB8128:EE_ X-MS-Office365-Filtering-Correlation-Id: 61909554-2875-4dce-f921-08dcc3aae9f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|36860700013|376014|1800799024|921020; X-Microsoft-Antispam-Message-Info: KP4L1JWxRIeBpE0EEJO8LpP5IlZX6HTTBy+87aBKiwKesa0foNZXpOPd+2Hdo58fZbj/1bkOQ0/7w2eUfvi3no+csR/v5S1h5IxXiC+zULrTwYxO4rVSj7NgCBS5L+EbRCdca/+pv9VYd1Dd85ERLMsAA4ypNYvNFMtwmblFpjHIzuf4Zrbq0lpS7nwszZzs4a93u9+HvkLLz528joXOhm2B+WU45K1ymnc8nlqO6TbVIk7x+H7KHH61Szp4VoVJfWyiFx6FPXEiTs/Ie+TZ5yDzhYjefpckFPoBY2ovcAPolZeG3bfV/dRvWonrZaRVjWPDUPYT0AVjFSr+L++cnODjapESASOqaBDDB7DZ6cskcdTksGlpBXuvgwfpsPTk0uMRtVkWWB1efj9HMa6OzutwqNIxT6S3RjZ1E/LWpEoR7AYhILzdmXseg3M9s0wZt2qTvkdcA2XeE4Z0ndbhPhIYL7TuJXhT8MRsKyJZy2fBnHgDcHDA38g2ObURwu81uPFyWxjE8AA7pncDcOhqR0VvJW1BtsBWo66E+Afvv80PlBUwn6tTWXDMHw62dnz6JOtDMJqmgWv3DJ+gpAzUE3olkHq0gcQTHA3o27mT7bdQNlwkYnGe+ktEvv2WCAP0rWosncovNasmX8T3rG8zJfeKCpwgUXnDy5Vzc9GN26oCS5jYjV0msCXQ9igCa0kmKb5BramzJTjk0jrgN2e9XYeefoAfp6uV2vlBvJBN5bW84EDPF6oRIibtV3ppKxFqcpClkbHjjtZJ7UTCPii1jrgK2R9o8mv3o+/tX7/3Mkzel3NqWTNzWO3RlTdALh48kNbdkK9RxuZ19cNicF6Mp2EbBuPBqHZr4ywBBQvvIY9JkBtdC7svUOBDddo7U072s8qdpJDchFycruSv1QZYZqWmDXVPDmq4qYAj/4e5HHOLFHd9w8kOpyEDJfs1yEof3Zd5cTuTfpPFlsgrYGfStmiCOMEW3O44bs4Qo6MJivQ5GusiGAB1cZDgElhlrBxSd4BrlPVu2CKLRmSDEqdbeGZW7yFbN/GkKZ5KVnb8w4DG0ct5C4x7EA9SbpNaxjHoaUnm6UTUj5yh8RkN9+61b4BTsZ6A0a7SNMST4VoDdhzb/0NIlFM3RJCGDgARdh2gZQgcDjNoHAIpDpNFFJCGMpsMrFCGQX4E+drVjHc/lA8Rju9fzKis5LYgDsNKN/lz/fTKQiOgm3sTdJ6OM5FPAkp1j9xV2+OurWs04O+ttCYJZiSKUnn6z521fzyoc5o/0FgvbJL8GklbR+2t+Z1Z1pNLULBK+ewdVc2ca+C4GrTG/ayHLCHhxtHbcj9B9CvQ0HBr7k9ocMFA2awCdBeG5fhomUF/nxCLsBQOIS7/IH0nc0ZR8ObZfQ4QFdrhoWBJW1D+s/VFzvGKr1EG1kU3DKe//lFD/0SIraPo6OBPdY3eak84qie+VKd9A5kao5HG 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:(13230040)(82310400026)(7416014)(36860700013)(376014)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 19:36:41.5726 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 61909554-2875-4dce-f921-08dcc3aae9f0 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: BL02EPF00021F6D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8128 phys_base needs to be set for __pa() to work in xen_pvh_init() when finding the hypercall page. Set it before calling into xen_prepare_pvh(), which calls xen_pvh_init(). Clear it afterward to avoid __startup_64() adding to it and creating an incorrect value. Signed-off-by: Jason Andryuk Reviewed-by: Juergen Gross --- v2: Fix comment style Add Juergen's R-b s/LOAD_PHYSICAL_ADDR/_pa(pvh_start_xen)/ in case they differ --- arch/x86/platform/pvh/head.S | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index ba4d0eab4436..14b4345d9bae 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -125,7 +125,20 @@ SYM_CODE_START_LOCAL(pvh_start_xen) xor %edx, %edx wrmsr + /* + * Calculate load offset and store in phys_base. __pa() needs + * phys_base set to calculate the hypercall page in xen_pvh_init(). + */ + movq %rbp, %rbx + subq $_pa(pvh_start_xen), %rbx + movq %rbx, phys_base(%rip) call xen_prepare_pvh + /* + * Clear phys_base. __startup_64 will *add* to its value, + * so reset to 0. + */ + xor %rbx, %rbx + movq %rbx, phys_base(%rip) /* startup_64 expects boot_params in %rsi. */ lea pvh_bootparams(%rip), %rsi From patchwork Fri Aug 23 19:36:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13775754 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 AA3EFC5472C for ; Fri, 23 Aug 2024 19:36:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.782600.1192124 (Exim 4.92) (envelope-from ) id 1sha5X-0002rW-Vq; Fri, 23 Aug 2024 19:36:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 782600.1192124; Fri, 23 Aug 2024 19:36:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sha5X-0002rP-RZ; Fri, 23 Aug 2024 19:36:47 +0000 Received: by outflank-mailman (input) for mailman id 782600; Fri, 23 Aug 2024 19:36:47 +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 1sha5X-0002Oa-81 for xen-devel@lists.xenproject.org; Fri, 23 Aug 2024 19:36:47 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2062b.outbound.protection.outlook.com [2a01:111:f403:2415::62b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 081d9907-6187-11ef-a50a-bb4a2ccca743; Fri, 23 Aug 2024 21:36:46 +0200 (CEST) Received: from BN9PR03CA0624.namprd03.prod.outlook.com (2603:10b6:408:106::29) by IA1PR12MB6089.namprd12.prod.outlook.com (2603:10b6:208:3ef::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18; Fri, 23 Aug 2024 19:36:42 +0000 Received: from BL02EPF00021F6D.namprd02.prod.outlook.com (2603:10b6:408:106:cafe::6f) by BN9PR03CA0624.outlook.office365.com (2603:10b6:408:106::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.18 via Frontend Transport; Fri, 23 Aug 2024 19:36:42 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF00021F6D.mail.protection.outlook.com (10.167.249.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7897.11 via Frontend Transport; Fri, 23 Aug 2024 19:36:42 +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.39; Fri, 23 Aug 2024 14:36:41 -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.39 via Frontend Transport; Fri, 23 Aug 2024 14:36:40 -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: 081d9907-6187-11ef-a50a-bb4a2ccca743 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=B3sMVq8VN0eDPtNrm6Y5209AmqJDoEaZnWPVYtlW0agBUGgv6vTxEW5RPrn+G4JtOaFvoyjLQ+QBvZSuTnYE3bXJgKs40/v5g12sbZX1VniIG9Z/eylVwOI9YJ11aHdObwx4uLrtjVDfuaIXR0e6p+XvWtzTT1zu1Dl6iFxQLNLQ0KZgE3RluBWK8NEdn5DRXT7SlDzWqhat/im87jmInZmLPZbitUmZURrhOWeOni0Dwhv5wDE/PU2Oj2a2yo+pSPf18O6Fwy4t5a3B0Bn7BWTR+bdG11kM3sZRTA+MySklJXENQssqIs2vcj77bTJa/fBlMZQhgPeH6jM6ZroqCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=3WNcTBJWFqlSsl7h7qLZb7kjFufC1sLILMFbSKVwKI0=; b=sFMohX8S/ImnJ3sw6spbBG4PjYY8gVTWZrsVJyAa0ajT7qbLecV1/OItoQ2OoFFFlfGO3Gow+D5YfD2fQcBSIYyWejKfyNAKA8G/FksM2TpTY6jiw16x8MksEqqVw5MKsno4yOgzmGZMBFdAVMwej3x/D4wB8EobM4quR+6lwdeUsVhb/dEDQFMcjKSt2k/n2pb9NpHSJXj/cQTvXVwqKMlLY7WrQ3ZrgDRkVWIcQSwcR9NXozdyIyoFPtAN+768ASQpuQvx8X/LaO9gZYPa2fzqUvHVYIqbrBOfdQhAhZgCZSwMJW8vPrEEgFaaJ2xdPJX4t5uUUnsCDIwZLmBlkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=3WNcTBJWFqlSsl7h7qLZb7kjFufC1sLILMFbSKVwKI0=; b=SuKBJWW2TgJPv/AzenI46xrSKx4hRZkVhavDABFrHESx3llNncuJ6RMZAceYvz3D6Jm1gOTLPzmzPCIfDCrCLnPpo26iax+b7+tFpdfSiEXOztmWzsnQ55FZjBvFILvC9IbOF2XBb2LzR7m0NDnjERFOXxQW8sHtLYxAEDhjmDY= 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: Juergen Gross , Boris Ostrovsky , Thomas Gleixner , "Ingo Molnar" , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" , Stefano Stabellini , "Oleksandr Tyshchenko" , Paolo Bonzini , Brian Gerst CC: , , "Jason Andryuk" Subject: [PATCH v3 4/5] x86/kernel: Move page table macros to header Date: Fri, 23 Aug 2024 15:36:29 -0400 Message-ID: <20240823193630.2583107-5-jason.andryuk@amd.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823193630.2583107-1-jason.andryuk@amd.com> References: <20240823193630.2583107-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: BL02EPF00021F6D:EE_|IA1PR12MB6089:EE_ X-MS-Office365-Filtering-Correlation-Id: 3b003c65-0cc8-4f84-cd82-08dcc3aaea46 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|36860700013|1800799024|921020; X-Microsoft-Antispam-Message-Info: FDkRxvEsmk7D7g/8OineGBnboTwpnh3LX7xNXaMrANKqOxE6Ji4PBzHBewAK/jUfg9tKXlgvCzzDjt09xmKeTQ/tc4O9houcL4XpbvS++G/kV9tYJpW7f2rWo1iT/pe7yvhEJvKebrp2dxCHnyAPqOdUgoVT0rWjsSGEM64cStourjuRxVmdVtC6p4pQXzPZn2IuepiXpr+Cy/fulkzscrIXLyYN9WZsO42MLugy1HDv7yjj8uxsu9WHA97FOLyAtgIfz5Vf90dZYoGVcnnatAqsZBGXZ0OzQJv8MB0Gev+7TzUFKACoklyruxxfu3lEvmEUhJZw0ATqAacgnq1Im4oY2Q3wuDCCMBVvl/CBw8UcrE1MBFFBjtTMEyexgYAUVnFY4EVUcizDe9hK+EuIiqOsiq8Nqg+1UAK6mnKidXRphMNeUUqCfu/rXaR85VgYPL+LFKt1eKbPg6UKH0u6iRU8neCuXm347DNokj/VInOIx+unQAYJLfCb3Ij6iYMoCW20bFr4R/uDH3TfBumFSuYKOX8QmelLKUhN+ACk2bEb5xlZKA70UTLiEo5gP+OfveaMKhBxhdRhdSnJMBOa+Ccyhas+emkpcuZQ73RKbMLQelIsnDeeOnwSHasfsv/JYCOXCd14BVbSADE0ABlvGRGZcBFxRcEFzkRWN0KhezO1FSXtbeswhlOMYBv80gidzzqFt7IQOOeN76l+r10BNdAGjscMgeSI7KwInAO3a2QBMu+mC4lyyE03sPwaa3FZk3V5W3+iObnKuC5iR1ti6f8+PA61BardvHEXNTCJzHKCo1tYiH5rXIivDNCQ+DHrQeosoEIb92G/sdBwJ/JNKXENVCRX1nK5W+53stqjlzh6CpbZQuOpTCMF5jft66qoZfG4WUfCfW7m6q4oZRYyFJ1gHmshgeQbV1zBJ9wyjKjXy/lw/3dvWIGz0cpPr7Ym2RRdgcws4hyB1GeTHpJoCNtyxARWVDjm18F1usHAs2QKzagYPyX05Y3626rTVGCJtJPAYhvJ0wXTvokP+lTuiD986dZM2o9i+v+TY2GQ1Htl+hTwpOQVBQ+QAWfLUCmK7mog9mdspr0NcFM+8ubmnYH5hgOYmQPRmAWq2AcDmXrJF41ZIO+v/99IL+MrA+O/J+DDu0NyECUCsitHmmG9m3bFBx3AN99gB9bfcVHYActJjjk77CvMxkMFmy6HTSDMSi35W4Bxho/kn1+u8ynHmT/Soy3tPXmY8W5h4SlrDTVlpQD7yMpvWXtr8JYatmgXDZuUN8u/KvUKlFIWb8lzMXxoDaaqbpd9XQRfT848hd+8Y8a+VMXrGBzPAQkhhS0/jqyxPf2LOaw3aAUIkE/5dDsy9UHhkVG50gEPTeyQ3lhH2rovTOnf9JCD0by7zd25EbkJbMK7f0CW/K25a1MUcQCfmNcmD2w+OxWxEWIC2U2anTO7ZukxQ7/Uuv46wLqNfgYC9JMTAng6KhPcyeHJZg== 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:(13230040)(82310400026)(7416014)(376014)(36860700013)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 19:36:42.1508 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3b003c65-0cc8-4f84-cd82-08dcc3aaea46 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: BL02EPF00021F6D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6089 The PVH entry point will need an additional set of prebuild page tables. Move the macros and defines to pgtable_64.h, so they can be re-used. Signed-off-by: Jason Andryuk Reviewed-by: Juergen Gross --- v3: Add Juergen's R-b v2: Use existing pgtable_64.h s/-/ - / in pud_index() Did not add Juergen's R-b in case the header movement matters --- arch/x86/include/asm/pgtable_64.h | 23 ++++++++++++++++++++++- arch/x86/kernel/head_64.S | 20 -------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h index 3c4407271d08..72912b8edfdf 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -271,5 +271,26 @@ static inline bool gup_fast_permitted(unsigned long start, unsigned long end) #include -#endif /* !__ASSEMBLY__ */ +#else /* __ASSEMBLY__ */ + +#define l4_index(x) (((x) >> 39) & 511) +#define pud_index(x) (((x) >> PUD_SHIFT) & (PTRS_PER_PUD - 1)) + +L4_PAGE_OFFSET = l4_index(__PAGE_OFFSET_BASE_L4) +L4_START_KERNEL = l4_index(__START_KERNEL_map) + +L3_START_KERNEL = pud_index(__START_KERNEL_map) + +#define SYM_DATA_START_PAGE_ALIGNED(name) \ + SYM_START(name, SYM_L_GLOBAL, .balign PAGE_SIZE) + +/* Automate the creation of 1 to 1 mapping pmd entries */ +#define PMDS(START, PERM, COUNT) \ + i = 0 ; \ + .rept (COUNT) ; \ + .quad (START) + (i << PMD_SHIFT) + (PERM) ; \ + i = i + 1 ; \ + .endr + +#endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_PGTABLE_64_H */ diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 330922b328bf..16752b8dfa89 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -32,13 +32,6 @@ * We are not able to switch in one step to the final KERNEL ADDRESS SPACE * because we need identity-mapped pages. */ -#define l4_index(x) (((x) >> 39) & 511) -#define pud_index(x) (((x) >> PUD_SHIFT) & (PTRS_PER_PUD-1)) - -L4_PAGE_OFFSET = l4_index(__PAGE_OFFSET_BASE_L4) -L4_START_KERNEL = l4_index(__START_KERNEL_map) - -L3_START_KERNEL = pud_index(__START_KERNEL_map) __HEAD .code64 @@ -577,9 +570,6 @@ SYM_CODE_START_NOALIGN(vc_no_ghcb) SYM_CODE_END(vc_no_ghcb) #endif -#define SYM_DATA_START_PAGE_ALIGNED(name) \ - SYM_START(name, SYM_L_GLOBAL, .balign PAGE_SIZE) - #ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION /* * Each PGD needs to be 8k long and 8k aligned. We do not @@ -601,14 +591,6 @@ SYM_CODE_END(vc_no_ghcb) #define PTI_USER_PGD_FILL 0 #endif -/* Automate the creation of 1 to 1 mapping pmd entries */ -#define PMDS(START, PERM, COUNT) \ - i = 0 ; \ - .rept (COUNT) ; \ - .quad (START) + (i << PMD_SHIFT) + (PERM) ; \ - i = i + 1 ; \ - .endr - __INITDATA .balign 4 @@ -708,8 +690,6 @@ SYM_DATA_START_PAGE_ALIGNED(level1_fixmap_pgt) .endr SYM_DATA_END(level1_fixmap_pgt) -#undef PMDS - .data .align 16 From patchwork Fri Aug 23 19:36:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13775755 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 0D72AC5472F for ; Fri, 23 Aug 2024 19:37:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.782602.1192144 (Exim 4.92) (envelope-from ) id 1sha5a-0003Nn-Kj; Fri, 23 Aug 2024 19:36:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 782602.1192144; Fri, 23 Aug 2024 19:36:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sha5a-0003NZ-H1; Fri, 23 Aug 2024 19:36:50 +0000 Received: by outflank-mailman (input) for mailman id 782602; Fri, 23 Aug 2024 19:36:48 +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 1sha5Y-0002Oa-OF for xen-devel@lists.xenproject.org; Fri, 23 Aug 2024 19:36:48 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2060e.outbound.protection.outlook.com [2a01:111:f403:2417::60e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 08dcf510-6187-11ef-a50a-bb4a2ccca743; Fri, 23 Aug 2024 21:36:47 +0200 (CEST) Received: from BN8PR03CA0030.namprd03.prod.outlook.com (2603:10b6:408:94::43) by SA1PR12MB6822.namprd12.prod.outlook.com (2603:10b6:806:25d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Fri, 23 Aug 2024 19:36:44 +0000 Received: from BL02EPF00021F6C.namprd02.prod.outlook.com (2603:10b6:408:94:cafe::ce) by BN8PR03CA0030.outlook.office365.com (2603:10b6:408:94::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21 via Frontend Transport; Fri, 23 Aug 2024 19:36:43 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF00021F6C.mail.protection.outlook.com (10.167.249.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7897.11 via Frontend Transport; Fri, 23 Aug 2024 19:36:43 +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.39; Fri, 23 Aug 2024 14:36:43 -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.39 via Frontend Transport; Fri, 23 Aug 2024 14:36:42 -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: 08dcf510-6187-11ef-a50a-bb4a2ccca743 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vrLdvVAYNnK0GXqQoPQm4dyZhaTVDxuvnrEqN6inGJdNrYhU4z25N2fHaSwOxCwifPjhi/rlVRt2HPZvA6l5MlwALoGjQhhRwkpTF5leYyv0YjU4iW4HlsrtbqtQZtZgwxaYo+6naUP3KKVW31PU6ArynM8DedR23wRiLoPIbqrBhfknUFxcJomkrRkPNDno654xRrKfeCmZnStmauXwWLOpfxhWyKqMLPBDsnr4xfxzx/i9Sv7OSD+WSWwrummQ2g874nS4owIPGFVRg1e1Em7DJFidqK0/dxJjrNJ0pZgIBQzPEsLq9Cj5c1SwNljktDnQSszUvgjqTxEUXiFhJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=54RpaQe43r3m1s3jgsbEk0pLsaUFOLQtoTRxmGcRr5Q=; b=xU8bLOxXWQBIDXUnfFu0V6bIeC69ocSKPjGVRgA12hHb/79sN9Tf/x1UhCWHVEexeJpVhBU2FJfDNCXG4BPE/D+Ay88kcI+463RqKZ8KTgn04s7vDMyj9o07874oiHq2MKTc9nJlA28/c609c8nYskmNi7x7/E/rrR0XSwM7MQdowiFAQ9Oiy96Oyr4XWD0eFIE1/gP8tbyXewy6DEhPAfS5bdap5mNfY3KeEBf9Jdw1McqbVOmF1QPp4+IZOMxxNdGGCT+Q+mV0rp0zP1MR0FmgzxnLnOodIAlGWa1O1LQqGhNfflbX1CXgxKoRB1RTAPUNCbeL95qTON4OzM4lzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=54RpaQe43r3m1s3jgsbEk0pLsaUFOLQtoTRxmGcRr5Q=; b=FjkcPNpZ1ZKQqoTmzy3n3sNLAaQ/2kAC31pgibFrQ2PikK3IWsJNhQ5rQIYqWXCuP/zqeW6Jb4nKuFHrfSkT4xTYkTTLrXK+Lf67f+fvNSFW8/+eW2shQVhYnrZvgtVRmf1NeIHJHSCxMeHQGhFbyIh4qeYDf8LpK8AzaFlb4Ic= 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: Juergen Gross , Boris Ostrovsky , Thomas Gleixner , "Ingo Molnar" , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" , Stefano Stabellini , "Oleksandr Tyshchenko" , Paolo Bonzini , Brian Gerst CC: , , "Jason Andryuk" Subject: [PATCH v3 5/5] x86/pvh: Add 64bit relocation page tables Date: Fri, 23 Aug 2024 15:36:30 -0400 Message-ID: <20240823193630.2583107-6-jason.andryuk@amd.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823193630.2583107-1-jason.andryuk@amd.com> References: <20240823193630.2583107-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: BL02EPF00021F6C:EE_|SA1PR12MB6822:EE_ X-MS-Office365-Filtering-Correlation-Id: 8f124fd5-18ca-4ed9-1407-08dcc3aaeb49 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|7416014|36860700013|921020; X-Microsoft-Antispam-Message-Info: kfGL76HojrxbYgwwBDmpX+cNmS9nZnQffV2efutiCAaLOqj5QxTU9Q2qUtLeAxzp4zhDdm2rdA76xJSyEpx+5PpSRBQ/jG7MNBzGNQ4m5jFZGEQ8lU26+PPmTAa7l/4dD89wjkkG7bK/z3Gg0HsM6saP3V4HBQY522fBY10aOsiJL+0bQnrH7jCr9iot1JeY0g2Ijo3frjQLfCZT5/37eFgp0s+UnbYmR6Wcat0R3uRSED4e39qmsRzk6ntGdSDwqWF06IfQEU/8EMMS6FVm+dYECz/Kds+SR6hJk1KfF07xxPamdRPUmvj1y+oYKpNHGNsWLoWBqc4U0RBFoXUU5ITLWGtF95mCNgxkhOI1ngxvvbCWDKGspH1EnGU4OuuY6GHBzXOLqOq+k9IjYXjCGystsXnfDyY8UnBukM/Xj9KuDyyFcKKLteXht6bnYnu9tCE+lBB+/DWl8FwFVCwygUMk12ezD27c5e/tzR1ppddxQ29DQuHiJErfesky7ZsE2ig35DLSXb46vcKKo0nMlT+GgXMfb5gGVnBC9jLGfQRuorZNKvdAkjiVynrE2D6EEoMQLe3BlpLMWZ57QXAHJVADlHcD/QTsDP7R7I9Zrh1HudEUUahw/A0ms+rXYbGUJgk4vVqYiSKFFmLbSXZtOw/hAC7+76AwOSnUtRrDkyLYkrqlOHnEjEchPkEh9MGNTaM+uo8nr0Gllb0PDWyTjxyG3Pra3+qOmIaes5FzyTtNddDRb6N67sSvsSUVmPhP885XhdG4t3RTRS8KwAIFziFHyXMn8wpvB5zPacieogWW14Zgl/NNy+zHRBZQtH3nKeXZE6AZGvLNOeXv+nn6rFgnwT2JDJ2gDy9FsZLuBARyeUuWmGG8pxxAnngrrsCyh9xZ/dH8FAuOxolOeYRMa71wFunkBH/HF3ahNOKnoXt+534ZZx4gVGr0b/ZXT7MER9hY1eVON+WHCXML32eQL2YHxwbhOYmbJgHjwtjbqJtiTJsHjJfmrThaulR2E9zk1XXY+Ng4KJ3EonWwqf53Gt8h7EpysOIDy7P+fhVRnf2wNNZSmVogw7RTs0T4xh/GhrESOpTBMWldS+3KzfY2tjKzygpYaiJn8QJtQ4bdF/ya+hYj/bTkWhHmbX+UG2cCnx36SST3LdOAim9NwbLomj8Ea04JM4JKRb3eIlhyG9S7sLTpZZJQayJCLYsUfs2QNwDQwvkgm7eUhvAZx1blXDii66hMXcOHeJCH2vrzeec4+bBk0YsnNOtVwDtBm/33D8tZJDczYy2y+1oMeTO4s+VwE2x2vAZGZuJCUpn6eyvDjhlN7BIIlVWGiOsBeWTnlDiFZxK0ZKf4/cy2IYqZlx0eoYPyCehcHTYQ/xMEYYFcXyELKqpzrc5C0JapW8quVx+LsZnx/9Yrcue+Vzt/DHVVlV5smDZEHGr0/A1hc6VoX8POkkJW1FEipT8TfWHE 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:(13230040)(1800799024)(82310400026)(376014)(7416014)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 19:36:43.7965 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f124fd5-18ca-4ed9-1407-08dcc3aaeb49 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: BL02EPF00021F6C.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6822 The PVH entry point is 32bit. For a 64bit kernel, the entry point must switch to 64bit mode, which requires a set of page tables. In the past, PVH used init_top_pgt. This works fine when the kernel is loaded at LOAD_PHYSICAL_ADDR, as the page tables are prebuilt for this address. If the kernel is loaded at a different address, they need to be adjusted. __startup_64() adjusts the prebuilt page tables for the physical load address, but it is 64bit code. The 32bit PVH entry code can't call it to adjust the page tables, so it can't readily be re-used. 64bit PVH entry needs page tables set up for identity map, the kernel high map and the direct map. pvh_start_xen() enters identity mapped. Inside xen_prepare_pvh(), it jumps through a pv_ops function pointer into the highmap. The direct map is used for __va() on the initramfs and other guest physical addresses. Add a dedicated set of prebuild page tables for PVH entry. They are adjusted in assembly before loading. Add XEN_ELFNOTE_PHYS32_RELOC to indicate support for relocation along with the kernel's loading constraints. The maximum load address, KERNEL_IMAGE_SIZE - 1, is determined by a single pvh_level2_ident_pgt page. It could be larger with more pages. Signed-off-by: Jason Andryuk Reviewed-by: Juergen Gross --- v3: Include asm/pgtable.h to avoid 32bit build failure v2: Use some defines: PTRS_PER_PGD, PTRS_PER_PMD, PAGE_SIZE Add some spaces around operators and after commas Include asm/pgtable_64.h s/LOAD_PHYSICAL_ADDR/_pa(pvh_start_xen)/ in case they differ --- arch/x86/platform/pvh/head.S | 104 ++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index 14b4345d9bae..64fca49cd88f 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -102,8 +103,47 @@ SYM_CODE_START_LOCAL(pvh_start_xen) btsl $_EFER_LME, %eax wrmsr + mov %ebp, %ebx + subl $_pa(pvh_start_xen), %ebx /* offset */ + jz .Lpagetable_done + + /* Fixup page-tables for relocation. */ + leal rva(pvh_init_top_pgt)(%ebp), %edi + movl $PTRS_PER_PGD, %ecx +2: + testl $_PAGE_PRESENT, 0x00(%edi) + jz 1f + addl %ebx, 0x00(%edi) +1: + addl $8, %edi + decl %ecx + jnz 2b + + /* L3 ident has a single entry. */ + leal rva(pvh_level3_ident_pgt)(%ebp), %edi + addl %ebx, 0x00(%edi) + + leal rva(pvh_level3_kernel_pgt)(%ebp), %edi + addl %ebx, (PAGE_SIZE - 16)(%edi) + addl %ebx, (PAGE_SIZE - 8)(%edi) + + /* pvh_level2_ident_pgt is fine - large pages */ + + /* pvh_level2_kernel_pgt needs adjustment - large pages */ + leal rva(pvh_level2_kernel_pgt)(%ebp), %edi + movl $PTRS_PER_PMD, %ecx +2: + testl $_PAGE_PRESENT, 0x00(%edi) + jz 1f + addl %ebx, 0x00(%edi) +1: + addl $8, %edi + decl %ecx + jnz 2b + +.Lpagetable_done: /* Enable pre-constructed page tables. */ - leal rva(init_top_pgt)(%ebp), %eax + leal rva(pvh_init_top_pgt)(%ebp), %eax mov %eax, %cr3 mov $(X86_CR0_PG | X86_CR0_PE), %eax mov %eax, %cr0 @@ -198,5 +238,67 @@ SYM_DATA_START_LOCAL(early_stack) .fill BOOT_STACK_SIZE, 1, 0 SYM_DATA_END_LABEL(early_stack, SYM_L_LOCAL, early_stack_end) +#ifdef CONFIG_X86_64 +/* + * Xen PVH needs a set of identity mapped and kernel high mapping + * page tables. pvh_start_xen starts running on the identity mapped + * page tables, but xen_prepare_pvh calls into the high mapping. + * These page tables need to be relocatable and are only used until + * startup_64 transitions to init_top_pgt. + */ +SYM_DATA_START_PAGE_ALIGNED(pvh_init_top_pgt) + .quad pvh_level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC + .org pvh_init_top_pgt + L4_PAGE_OFFSET * 8, 0 + .quad pvh_level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC + .org pvh_init_top_pgt + L4_START_KERNEL * 8, 0 + /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */ + .quad pvh_level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE_NOENC +SYM_DATA_END(pvh_init_top_pgt) + +SYM_DATA_START_PAGE_ALIGNED(pvh_level3_ident_pgt) + .quad pvh_level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC + .fill 511, 8, 0 +SYM_DATA_END(pvh_level3_ident_pgt) +SYM_DATA_START_PAGE_ALIGNED(pvh_level2_ident_pgt) + /* + * Since I easily can, map the first 1G. + * Don't set NX because code runs from these pages. + * + * Note: This sets _PAGE_GLOBAL despite whether + * the CPU supports it or it is enabled. But, + * the CPU should ignore the bit. + */ + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) +SYM_DATA_END(pvh_level2_ident_pgt) +SYM_DATA_START_PAGE_ALIGNED(pvh_level3_kernel_pgt) + .fill L3_START_KERNEL, 8, 0 + /* (2^48-(2*1024*1024*1024)-((2^39)*511))/(2^30) = 510 */ + .quad pvh_level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC + .quad 0 /* no fixmap */ +SYM_DATA_END(pvh_level3_kernel_pgt) + +SYM_DATA_START_PAGE_ALIGNED(pvh_level2_kernel_pgt) + /* + * Kernel high mapping. + * + * The kernel code+data+bss must be located below KERNEL_IMAGE_SIZE in + * virtual address space, which is 1 GiB if RANDOMIZE_BASE is enabled, + * 512 MiB otherwise. + * + * (NOTE: after that starts the module area, see MODULES_VADDR.) + * + * This table is eventually used by the kernel during normal runtime. + * Care must be taken to clear out undesired bits later, like _PAGE_RW + * or _PAGE_GLOBAL in some cases. + */ + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE / PMD_SIZE) +SYM_DATA_END(pvh_level2_kernel_pgt) + + ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_RELOC, + .long CONFIG_PHYSICAL_ALIGN; + .long LOAD_PHYSICAL_ADDR; + .long KERNEL_IMAGE_SIZE - 1) +#endif + ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, _ASM_PTR (pvh_start_xen - __START_KERNEL_map))