Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4088880pxk; Tue, 29 Sep 2020 14:06:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyad7uJ9yhvRIMWPdVjAm0j/baD4hDVknTDbkBxpU7CN8l7D5hCwu50eMBXiQSUWJqMlswV X-Received: by 2002:a17:906:c10c:: with SMTP id do12mr4448125ejc.527.1601413595545; Tue, 29 Sep 2020 14:06:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601413595; cv=none; d=google.com; s=arc-20160816; b=AW7xX0h2eVaVEHPVvE5vsPzBT5zMpeliHh6kV4EvNJSYDakg4lMYPlm1Qe84hRjIXL HoiGClj8pY2kRm9Z8plHmz3yVXVZxzaEW6o9GtC6p5Uj/3u1dXt3rgRnHNxRiQtE/ZO/ RAgqQjsHenNxi2Uvpii3KAaKoS4HXtfuT/oskLIbiA5heFNeMripHOmfQWTZItEh36RV Xc8Q08djT5vwdZEL7irlR7x8mNHL9rnNnBATkPP381KrzW0z0NTGZQNFKVl22GzWn6mF 33bh4RP7+0Id6z8+gordsJySsKgzgnUYLPmde5iqSf7fALZEghAUSaY0XELF2tC4a9Yh LflQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=MXHCjm2f4B3C88ZBMrTBGAoyRnpIg67/FPZnMRlWhj8=; b=RkrC48P1B23UKmyXamuEl0l8okQEBRkfMNVS+uN35rfo8KSyvjmSUHn3LmVPT2EhlC HTPXz3XucRA6erGbJu3ZDu7dYN8ruM+dynKqk/WVfvaTY3tkyiGyr6NOodaRntkkFLmJ SgNvf7XMSRqZBBhfVEsNUIzeO0w3mSNQyA76VIhC54bKUtMBY07Z2vDN928FlmLwxb1t M5AOJgpfuDD3lnKMn89t1WlAA8dj8b76jKdS6/kDRCr0k8fjfwPPqumsK2aNtlcAVMRa NQ2OAYfHG+njLTolry1kgbZemfQu6Mv1+3h91u10Y+hgpoYRIpKhRYgNn6eHAPfcRFju KhmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r6si3422742edm.211.2020.09.29.14.06.12; Tue, 29 Sep 2020 14:06:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729375AbgI2VE6 (ORCPT + 99 others); Tue, 29 Sep 2020 17:04:58 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:32857 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbgI2VE6 (ORCPT ); Tue, 29 Sep 2020 17:04:58 -0400 Received: by mail-qt1-f194.google.com with SMTP id a4so4862801qth.0 for ; Tue, 29 Sep 2020 14:04:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MXHCjm2f4B3C88ZBMrTBGAoyRnpIg67/FPZnMRlWhj8=; b=WidYGR55xyS8OOEXMowb96/LuIE1QRhyf3UP+fFmBzfEClfdPjg1XOzoko3g04U66O KV9YwtiLaXC+RijZ95iZP5yJEOJIPAbhFq0wX6a+J+p4M2HT3I5nXJAG0tlDBxtPMOTG tZhi8lprXUud5ow5UdtE/Rhor7AEXyn+L8K2vMsufqkjS84Ff8pZwlbgmrPqi7JaEgkV 6FALRIDKDpUHmSHUMadb2r9g6NjVcCChy6yyZbl7EWQ9bh+Ll63owxkRxJvBAFyN5mwM wPWEhjgMdDdtIoWnG9/siSSejar5cNxzM7/dvvJH18bScVk4TqrKjTUdCtr6Gq9XmbZo YEUA== X-Gm-Message-State: AOAM530WhlVhqcIUDQDPPvpzzzy9yfbgQDlFMUXDLRaPIEzJvxb3tXPe SB1KioJayVDheLF+szhrghXqPjbFii3PlA== X-Received: by 2002:ac8:1387:: with SMTP id h7mr5495384qtj.386.1601413496799; Tue, 29 Sep 2020 14:04:56 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id s20sm6049524qkg.65.2020.09.29.14.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2020 14:04:56 -0700 (PDT) From: Arvind Sankar To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Ross Philipson Subject: [PATCH] x86/boot: Place kernel_info at a fixed offset Date: Tue, 29 Sep 2020 17:04:55 -0400 Message-Id: <20200929210455.2718827-1-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are use cases for storing the offset of a symbol in kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header in kernel_info. Since commit (note: commit ID from tip/master) 527afc212231 ("x86/boot: Check that there are no run-time relocations") run-time relocations are not allowed in the compressed kernel, so simply using the symbol in kernel_info, as .long symbol will cause a linker error because this is not position-independent. With kernel_info being a separate object file and in a different section from startup_32, there is no way to calculate the offset of a symbol from the start of the image in a position-independent way. To enable such use cases, put kernel_info into its own section which is placed at a predetermined offset (KERNEL_INFO_OFFSET) via the linker script. This will allow calculating the symbol offset in a position-independent way, by adding the offset from the start of kernel_info to KERNEL_INFO_OFFSET. Ensure that kernel_info is aligned, and use the SYM_DATA.* macros instead of bare labels. This stores the size of the kernel_info structure in the ELF symbol table. Signed-off-by: Arvind Sankar Cc: Ross Philipson [0] https://lore.kernel.org/lkml/1600959521-24158-8-git-send-email-ross.philipson@oracle.com/ --- arch/x86/boot/compressed/kernel_info.S | 19 +++++++++++++++---- arch/x86/boot/compressed/kernel_info.h | 12 ++++++++++++ arch/x86/boot/compressed/vmlinux.lds.S | 6 ++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 arch/x86/boot/compressed/kernel_info.h diff --git a/arch/x86/boot/compressed/kernel_info.S b/arch/x86/boot/compressed/kernel_info.S index f818ee8fba38..c18f07181dd5 100644 --- a/arch/x86/boot/compressed/kernel_info.S +++ b/arch/x86/boot/compressed/kernel_info.S @@ -1,12 +1,23 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #include +#include "kernel_info.h" - .section ".rodata.kernel_info", "a" +/* + * If a field needs to hold the offset of a symbol from the start + * of the image, use the macro below, eg + * .long rva(symbol) + * This will avoid creating run-time relocations, which are not + * allowed in the compressed kernel. + */ + +#define rva(X) (((X) - kernel_info) + KERNEL_INFO_OFFSET) - .global kernel_info + .section ".rodata.kernel_info", "a" -kernel_info: + .balign 16 +SYM_DATA_START(kernel_info) /* Header, Linux top (structure). */ .ascii "LToP" /* Size. */ @@ -19,4 +30,4 @@ kernel_info: kernel_info_var_len_data: /* Empty for time being... */ -kernel_info_end: +SYM_DATA_END_LABEL(kernel_info, SYM_L_LOCAL, kernel_info_end) diff --git a/arch/x86/boot/compressed/kernel_info.h b/arch/x86/boot/compressed/kernel_info.h new file mode 100644 index 000000000000..c127f84aec63 --- /dev/null +++ b/arch/x86/boot/compressed/kernel_info.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BOOT_COMPRESSED_KERNEL_INFO_H +#define BOOT_COMPRESSED_KERNEL_INFO_H + +#ifdef CONFIG_X86_64 +#define KERNEL_INFO_OFFSET 0x500 +#else /* 32-bit */ +#define KERNEL_INFO_OFFSET 0x100 +#endif + +#endif /* BOOT_COMPRESSED_KERNEL_INFO_H */ diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S index 112b2375d021..84c7b4de489e 100644 --- a/arch/x86/boot/compressed/vmlinux.lds.S +++ b/arch/x86/boot/compressed/vmlinux.lds.S @@ -7,6 +7,7 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT) #include #include +#include "kernel_info.h" #ifdef CONFIG_X86_64 OUTPUT_ARCH(i386:x86-64) @@ -27,6 +28,11 @@ SECTIONS HEAD_TEXT _ehead = . ; } + .rodata.kernel_info KERNEL_INFO_OFFSET : { + *(.rodata.kernel_info) + } + ASSERT(ABSOLUTE(kernel_info) == KERNEL_INFO_OFFSET, "kernel_info at bad address!") + .rodata..compressed : { *(.rodata..compressed) } -- 2.26.2