From patchwork Mon Oct 31 15:10:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 13278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2374066wru; Mon, 31 Oct 2022 08:22:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4d9D2ksmqdbMg2pNi9Ob+qv/mAl+ZD3AHPZde30GZgpTdpYGbsauZzqG5+HdjgrZnkEIxq X-Received: by 2002:a63:188:0:b0:43c:22e9:2d10 with SMTP id 130-20020a630188000000b0043c22e92d10mr13192185pgb.12.1667229735101; Mon, 31 Oct 2022 08:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667229735; cv=none; d=google.com; s=arc-20160816; b=eTB+12qHxP2oK5PNO4pxy4KabNNj6yll9ClMo65INAB2V7uigr20w/hh05ai2JSQER vHNP1PAYsuKs8iA7zvDSKkUQj/f3QmXFXg3+X54N5j7rGFrQgMktdeznN0IriedJ+6vN XAInC+M8APK6FMkgFsK+YPAK5qWaJieH9yq1H9Vb51Py4qAllGnbrL0U5nqNWd+GjKRl FlsAePA1H/aH61HWF77FmcUAsSbQFY9yhHwa82Kshn5Z3YcvJNXtsZQtes5ZTK402Jja Mq70beZklqb9CFMIodnLDSPpFsRxSP7PF7Ki/aDXCMEU7xhyVkaHocEJ7BcZ4+VBVVa2 CrJQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YPaNExJY5aXN5hm+eJpW6ixd294/8+QQhE3/rnDnAEE=; b=BTJf2cWd6yu/kbDPqxOaSkDsRXGTvlUSCUcaHVmFzy3VNKh88Q8iCnxkfK2RD5ir1N JGrtL5m8Y28BvI19WP7f9t8UKJWsdfdJHahvxEoJBqoN+heoj7z9yAH+RJjFfT/BtUM2 etZtrpUhA8Boa9HKstvahksAPV4ivOQ9IpR+qoUFZvIssUS/HDskbbXlqtubmyPu2WX4 +D/q7yv5eiwxS6Gy2w8UlRF1GJLfOc39xBCfCTGzfs1y258nmcHkLTPW+H1VpOczhp7K YIPRoQz84b10wVsvCfnFn3ixoUzR7+RIBZNiqDjWrtvX/+1w6JkHp4gjL/V7VBzvent7 HdnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J0oKhm7W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv14-20020a056a00414e00b0056515a324adsi8779288pfb.90.2022.10.31.08.21.49; Mon, 31 Oct 2022 08:22:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J0oKhm7W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231641AbiJaPQq (ORCPT + 99 others); Mon, 31 Oct 2022 11:16:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229839AbiJaPQk (ORCPT ); Mon, 31 Oct 2022 11:16:40 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BCBB11456 for ; Mon, 31 Oct 2022 08:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667229399; x=1698765399; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ij2hEDRZG6EMb0z+MYknc0l1TIq/FCdvq5UymJFqZws=; b=J0oKhm7WSP4v0rmrn1h9MkfD3e9V98o2lEcImV8v9p5RGIRc/dTgc/CU td8mlL0EEx76eB4nXn0qEKX7X7BnY3poHKqL5bBDhvb6kf/HHZQaceVQj UIvDcc4DaUnBVby1TQFjqgyJgAGhJ88XRxefAopNdAYMidrHKbmnjjdBV rSa6cXqgw9Hj4ekEBEoB450kFT4TBscO/z1E2hiqrvkoo7FLwqUrne7RF Brch808ZFAsCtRR+ELLA3lgBMH7bwgApKioJg620SqaKBNqdD5aza6df5 1DmNNZBSSIk5DBMJABUz6tHIBe09YDMbt7T2TxDIvRw4YT7S5ENs7BDNR Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10517"; a="373134131" X-IronPort-AV: E=Sophos;i="5.95,228,1661842800"; d="scan'208";a="373134131" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2022 08:16:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10517"; a="697045598" X-IronPort-AV: E=Sophos;i="5.95,228,1661842800"; d="scan'208";a="697045598" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga008.fm.intel.com with ESMTP; 31 Oct 2022 08:16:35 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 29VFGXGE008839; Mon, 31 Oct 2022 15:16:34 GMT From: Alexander Lobakin To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: Alexander Lobakin , "H. Peter Anvin" , "Peter Zijlstra (Intel)" , Tony Luck , Kees Cook , Masahiro Yamada , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] x86/boot: robustify calling startup_{32,64}() from the decompressor code Date: Mon, 31 Oct 2022 16:10:46 +0100 Message-Id: <20221031151047.167288-2-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221031151047.167288-1-alexandr.lobakin@intel.com> References: <20221031151047.167288-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748217086782379142?= X-GMAIL-MSGID: =?utf-8?q?1748217086782379142?= After commit ce697ccee1a8 ("kbuild: remove head-y syntax"), I started digging whether x86 is ready from removing this old cruft. Removing its objects from the list makes the kernel unbootable. This applies only to bzImage, vmlinux still works correctly. The reason is that with no strict object order determined by the linker arguments, not the linker script, startup_64 can be placed not right at the beginning of the kernel. Here's vmlinux.map's beginning before removing: ffffffff81000000 vmlinux.o:(.head.text) ffffffff81000000 startup_64 ffffffff81000070 secondary_startup_64 ffffffff81000075 secondary_startup_64_no_verify ffffffff81000160 verify_cpu and after: ffffffff81000000 vmlinux.o:(.head.text) ffffffff81000000 pvh_start_xen ffffffff81000080 startup_64 ffffffff810000f0 secondary_startup_64 ffffffff810000f5 secondary_startup_64_no_verify Not a problem itself, but the self-extractor code has the address of that function hardcoded the beginning, not looking onto the ELF header, which always contains the address of startup_{32,64}(). So, instead of doing an "act of blind faith", just take the address from the ELF header and extract a relative offset to the entry point. The decompressor function already returns a pointer to the beginning of the kernel to the Asm code, which then jumps to it, so add that offset to the return value. This doesn't change anything for now, but allows to resign from the "head object list" for x86 and makes sure valid Kbuild or any other improvements won't break anything here in general. Signed-off-by: Alexander Lobakin Tested-by: Jiri Slaby --- arch/x86/boot/compressed/head_32.S | 2 +- arch/x86/boot/compressed/head_64.S | 2 +- arch/x86/boot/compressed/misc.c | 16 +++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 3b354eb9516d..56f9847e208b 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -187,7 +187,7 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) leal boot_heap@GOTOFF(%ebx), %eax pushl %eax /* heap area */ pushl %esi /* real mode pointer */ - call extract_kernel /* returns kernel location in %eax */ + call extract_kernel /* returns kernel entry point in %eax */ addl $24, %esp /* diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index d33f060900d2..aeba5aa3d26c 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -593,7 +593,7 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) movl input_len(%rip), %ecx /* input_len */ movq %rbp, %r8 /* output target address */ movl output_len(%rip), %r9d /* decompressed length, end of relocs */ - call extract_kernel /* returns kernel location in %rax */ + call extract_kernel /* returns kernel entry point in %rax */ popq %rsi /* diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index cf690d8712f4..96ae5af29f49 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -277,7 +277,7 @@ static inline void handle_relocations(void *output, unsigned long output_len, { } #endif -static void parse_elf(void *output) +static size_t parse_elf(void *output) { #ifdef CONFIG_X86_64 Elf64_Ehdr ehdr; @@ -287,6 +287,7 @@ static void parse_elf(void *output) Elf32_Phdr *phdrs, *phdr; #endif void *dest; + size_t off; int i; memcpy(&ehdr, output, sizeof(ehdr)); @@ -295,16 +296,19 @@ static void parse_elf(void *output) ehdr.e_ident[EI_MAG2] != ELFMAG2 || ehdr.e_ident[EI_MAG3] != ELFMAG3) { error("Kernel is not a valid ELF file"); - return; + return 0; } debug_putstr("Parsing ELF... "); phdrs = malloc(sizeof(*phdrs) * ehdr.e_phnum); - if (!phdrs) + if (!phdrs) { error("Failed to allocate space for phdrs"); + return 0; + } memcpy(phdrs, output + ehdr.e_phoff, sizeof(*phdrs) * ehdr.e_phnum); + off = ehdr.e_entry - phdrs->p_paddr; for (i = 0; i < ehdr.e_phnum; i++) { phdr = &phdrs[i]; @@ -328,6 +332,7 @@ static void parse_elf(void *output) } free(phdrs); + return off; } /* @@ -356,6 +361,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, const unsigned long kernel_total_size = VO__end - VO__text; unsigned long virt_addr = LOAD_PHYSICAL_ADDR; unsigned long needed_size; + size_t off; /* Retain x86 boot parameters pointer passed from startup_32/64. */ boot_params = rmode; @@ -456,14 +462,14 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, debug_putstr("\nDecompressing Linux... "); __decompress(input_data, input_len, NULL, NULL, output, output_len, NULL, error); - parse_elf(output); + off = parse_elf(output); handle_relocations(output, output_len, virt_addr); debug_putstr("done.\nBooting the kernel.\n"); /* Disable exception handling before booting the kernel */ cleanup_exception_handling(); - return output; + return output + off; } void fortify_panic(const char *name) From patchwork Mon Oct 31 15:10:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 13277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2373705wru; Mon, 31 Oct 2022 08:21:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7DhQyByYaXoHb3SLKRICoPj7Txi88RAxMTWrvN3NdLDh+TeajZUy6qSLmMInslNGLmyXvt X-Received: by 2002:a17:902:d0d3:b0:186:9869:adb5 with SMTP id n19-20020a170902d0d300b001869869adb5mr15420976pln.105.1667229691957; Mon, 31 Oct 2022 08:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667229691; cv=none; d=google.com; s=arc-20160816; b=k/PAjQu5lMIHKKyKUd8rGnUGci6768nKzD7UYoEt3hHIUn61T25b+EU440dt7Bi/kY Z/3mLbRIqrAAdEI6bM0XJvGCjL2lrTm7m+lCSMB/AcOWdHz6TzNVJdqE8vXnc1JWWoKT cOHoiwzmIkdqM0+hzv3MnC7drRSEHryqX1LE0GGMYvtEChTTpiE9fmsMS6UlcZCnXUys pI6Ub5i12wBsylG+I6Ria96xlinre9nwisO/sxYKZaOEoS0pLFpEv/2YZeRiEtTLdhk7 m5Y6CvKm3E1SoPibO5cEVeob5oo/IGRM9rpsXCihUrNf8IPDXdj+d3l5251I7ob9HXlT mH6Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9CJEhvJoq5YSf0ez5B+7TfkASAmucwPS/1nNa7Wkyi8=; b=WSgM0QisFX+W81cXY5XoLfP6mCckrbbohv6pHG2QlIHM5yl2RR/2kzOWhQkAQl3wnL O3L3KfZ2bwY7t9uHdHCLS5DAHhF5IYHJE4Sv5gYZ1eKZ3nF+WeHlZKrpEJzqummlWm9v 69EX9HmCzG/T5VzETlCVf7ZyqeXlAa5Sx6YZ3vaX50lFQFwNgz35PSEgSD6nMJat6bIj FaHMuQEshXAgZ6gcKLzyuiU1fhYc3i1Gq6sZU2biain0l6GoATxNz2TXaEU2XAV+jGlu ljizvYuBXpbqSItoUe8cdp9UBWRLOpCXDgRoKhLLJ6GCWhybxZpBSTqaOEciE9modQus m8Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dl45j1K9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id il16-20020a17090b165000b00213bbb6751asi9466136pjb.112.2022.10.31.08.21.13; Mon, 31 Oct 2022 08:21:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dl45j1K9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbiJaPQo (ORCPT + 99 others); Mon, 31 Oct 2022 11:16:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbiJaPQk (ORCPT ); Mon, 31 Oct 2022 11:16:40 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD8011145B for ; Mon, 31 Oct 2022 08:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667229399; x=1698765399; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MkZ1KS2KjXParkaGXXA5TbN72uiwo7wOn2n9k1I1hVw=; b=dl45j1K9/LPemcfVLTSKUu+5DBVze3VLgl3TEy9WHCftIcqoUSt5awus AOnroXOQHXE1TfHplDZcJMPVE9vnLYwT2cX17thvFF3FwXhcXlIdTP2z7 +HDf4+Ir50eOL5+Y8Ug0Nt6ldDxNQZJbqetjZxEiePgjUmYof9kMXaPJe IbigIX6mMIRzwiHe7Dbfl14BpGh5p52PLzgugUUertHt88mAczTeo2Rgm Gluzr09hZI4BnKAac1K15SgkDXpeR1MufZFSqLTbeqQK9N6gxMhxrypUS WZ7Y2y5C4cfKHj+Y0T2SR0GCQ+5dX5m6qEjrgNTqG+dyTIk/+yW+xsu8x A==; X-IronPort-AV: E=McAfee;i="6500,9779,10517"; a="373134137" X-IronPort-AV: E=Sophos;i="5.95,228,1661842800"; d="scan'208";a="373134137" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2022 08:16:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10517"; a="697045600" X-IronPort-AV: E=Sophos;i="5.95,228,1661842800"; d="scan'208";a="697045600" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga008.fm.intel.com with ESMTP; 31 Oct 2022 08:16:36 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 29VFGXGF008839; Mon, 31 Oct 2022 15:16:35 GMT From: Alexander Lobakin To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: Alexander Lobakin , "H. Peter Anvin" , "Peter Zijlstra (Intel)" , Tony Luck , Kees Cook , Masahiro Yamada , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] scripts/head-object-list: remove x86 from the list Date: Mon, 31 Oct 2022 16:10:47 +0100 Message-Id: <20221031151047.167288-3-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221031151047.167288-1-alexandr.lobakin@intel.com> References: <20221031151047.167288-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748217041590687662?= X-GMAIL-MSGID: =?utf-8?q?1748217041590687662?= Now that x86 boot code is not hardcoded to the particular linking order, remove x86 files from the list and let them be placed inside the vmlinux according only to the linker script and linker preferences. Signed-off-by: Alexander Lobakin Tested-by: Jiri Slaby --- scripts/head-object-list.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/head-object-list.txt b/scripts/head-object-list.txt index b16326a92c45..405d2942898a 100644 --- a/scripts/head-object-list.txt +++ b/scripts/head-object-list.txt @@ -44,10 +44,4 @@ arch/s390/kernel/head64.o arch/sh/kernel/head_32.o arch/sparc/kernel/head_32.o arch/sparc/kernel/head_64.o -arch/x86/kernel/head_32.o -arch/x86/kernel/head_64.o -arch/x86/kernel/head32.o -arch/x86/kernel/head64.o -arch/x86/kernel/ebda.o -arch/x86/kernel/platform-quirks.o arch/xtensa/kernel/head.o