From patchwork Tue Nov 1 16:15:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 13763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3075039wru; Tue, 1 Nov 2022 09:32:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4LdUONk2MPD6DnhuQaQ1ErYjQMCJk5o/hcvdLMK3Ps3AAb5AKU8hofBtihXPzQCdlMmB4t X-Received: by 2002:a17:907:80a:b0:783:2585:5d73 with SMTP id wv10-20020a170907080a00b0078325855d73mr18853119ejb.642.1667320320184; Tue, 01 Nov 2022 09:32:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667320320; cv=none; d=google.com; s=arc-20160816; b=01zafG1gUDq0lUq0g/9/bzI160RDblDDk3m5pHAT7M2NbYNryD6Cu20ekWeRPawH9P OkLFGP+MsSNK6GEzNbe64GwOm0ZLRiB7wiRkNuRhXmvUX89GLJnOV+b101/Foa//aklW EMIpVviYkP62bOetg6gPcN+gr9bNr5VFIXpmJ4CxnvSddWEriSHWQnuviy2NP1SftZsh 6xhP5kMs8h6+AslJAwtEiZd0kzCgm5C1O9I6kgSDeAOCbK+LVd+9VbdXFvRvCuJfaytE Lt+TvUDI2Ez0OVFpLN8MKgje2bw+Qvmj2p8U1FI0XzkJPtk5SutBtwhXygqsLQC2UniG 2wOQ== 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=Ge/wA9d6ZJAjJfFKEPM1XiayIy0ruGSoHRxjsDvr/Lg=; b=LKPssaFIOOFOWzFzwH3h4uqW1asZ9G6Wj9qM1PhYFd/P71/eSMRoPjeOf8XJljoeXF gxYfLWdGWUOTF+wMIK18Qn2QOxskpnG69+8US30RwzlbF2n4e4/O8ha6DuIOxom+xEwr KYXs4BQCdmHK4nsYZ1UnpZrg90KRbVat1yJKDBMqInuaJRtmmYsahmo+PyFblawZjmdp /W/iQbBM0Zk3lIJ4snV9kY51yphetQTCbnOTFQ0YGncGZCLhInT746I7f397/76B0czY 74nkL0NWbiFGLHT5HGdy2yf72Cy32ljJ59yT/CjKWDn45mpq+De5/sFk4ioosFNFeaDm QXOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G54KAkfe; 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 o3-20020a170906288300b0078c0c866a18si9609296ejd.19.2022.11.01.09.31.36; Tue, 01 Nov 2022 09:32:00 -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=G54KAkfe; 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 S229930AbiKAQU2 (ORCPT + 99 others); Tue, 1 Nov 2022 12:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiKAQU0 (ORCPT ); Tue, 1 Nov 2022 12:20:26 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BB6C1C903 for ; Tue, 1 Nov 2022 09:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667319625; x=1698855625; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lbpBDH90w4tbkgFgWIYQaC3aPZqBsU4jJJZ0iR+lNew=; b=G54KAkfe6Izr8B/5/mVeQRm80hkkTeocrIxUoUoNlwxejCiyWHFeLS8A KF6dfu1I8TrC7qmzsTVY+aF+53QokPgcCB4X/zglZJaQuI/sVzsPt7bZD 2Ht+/uMbffXhTbqWVu5woY3jXpQ+fk3lvFKMgUFeSMOXLmOQf4Su2Uwmv dxRGjGTyFVUhz6wj3o3m2D/iuRr0DgaowbQwG2gqawMMPV6u0Z0z8gpiw LdVKwpF0mfZoWjr3tomDOLR97RqkQieCbO4nepBCruE/ibMym+91P04Ej v+Rsr6N+sEOdCynCrETuE0Je683SUWI92ys16Hp2JP9zhkIJYhCOfWgBk Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="309175943" X-IronPort-AV: E=Sophos;i="5.95,231,1661842800"; d="scan'208";a="309175943" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 09:19:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="628623930" X-IronPort-AV: E=Sophos;i="5.95,231,1661842800"; d="scan'208";a="628623930" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga007.jf.intel.com with ESMTP; 01 Nov 2022 09:19:38 -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 2A1GJa8B019884; Tue, 1 Nov 2022 16:19:37 GMT From: Alexander Lobakin To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: Alexander Lobakin , Jiri Slaby , "H. Peter Anvin" , "Peter Zijlstra (Intel)" , Tony Luck , Kees Cook , Masahiro Yamada , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] x86/boot: robustify calling startup_{32,64}() from the decompressor code Date: Tue, 1 Nov 2022 17:15:28 +0100 Message-Id: <20221101161529.1634188-2-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221101161529.1634188-1-alexandr.lobakin@intel.com> References: <20221101161529.1634188-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1748312071878582704?= X-GMAIL-MSGID: =?utf-8?q?1748312071878582704?= After commit ce697ccee1a8 ("kbuild: remove head-y syntax"), I started digging whether x86 is ready for 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. Tested-by: Jiri Slaby Signed-off-by: Alexander Lobakin Reviewed-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, 12 insertions(+), 8 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..2548d7fb243e 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,16 +287,15 @@ static void parse_elf(void *output) Elf32_Phdr *phdrs, *phdr; #endif void *dest; + size_t off; int i; memcpy(&ehdr, output, sizeof(ehdr)); if (ehdr.e_ident[EI_MAG0] != ELFMAG0 || ehdr.e_ident[EI_MAG1] != ELFMAG1 || ehdr.e_ident[EI_MAG2] != ELFMAG2 || - ehdr.e_ident[EI_MAG3] != ELFMAG3) { + ehdr.e_ident[EI_MAG3] != ELFMAG3) error("Kernel is not a valid ELF file"); - return; - } debug_putstr("Parsing ELF... "); @@ -305,6 +304,7 @@ static void parse_elf(void *output) error("Failed to allocate space for phdrs"); 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 +328,8 @@ static void parse_elf(void *output) } free(phdrs); + + return off; } /* @@ -356,6 +358,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 +459,15 @@ 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); + debug_putaddr(off); 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 Tue Nov 1 16:15:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 13764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3075060wru; Tue, 1 Nov 2022 09:32:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4MQd2+WltrqHWxXeCRIhtN7raLv3D5/ZzZ3mWgF7pwC5TWm8HNTdv17XWj/T3LwF9ADh8q X-Received: by 2002:a17:907:7e9e:b0:78d:f3b0:fc78 with SMTP id qb30-20020a1709077e9e00b0078df3b0fc78mr19368752ejc.478.1667320322407; Tue, 01 Nov 2022 09:32:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667320322; cv=none; d=google.com; s=arc-20160816; b=dAAxO2kLI/XHl/DDfIRowJA+kYw71ZuBzHPrrvpgub92h62YE0HBUAgOAB4ee+eVGE O88iCqSlbnvd3zaUMdkW3WTP6fbRc3y++knB6GhwIDcKNLongoFb8G3Tz52dbgxHFaaa pjqd/wo/219lhmD5fAPEHNG0bVAADwQ75C3RComQitkKXsf5mQkGzaYZC/jy6steY6Qb 9n2X8MW5+n448uoP08N0YbmlI9RvyjWVxvIemXCb62CL0INMnMAzt4fIdALyVYvYNvkL lo0Q3XFFdg5RsYZjq9/wrCSW0vC1f/823SBqcaG5Adj2xJX4Yb4IsUjKdSHx/B1qU+qu mdSg== 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=9Vm+MEk/cd/nC9+aV6Kw/4RmGAJnx8UcWnV5yaDaIbQ=; b=Ulz36EuzaDOnHYeIDNgNj+VGwojQy5zfQm0KclLXtPYxZMS6FWKFeTrwsDiXp4lPT7 G9HA/scHYNfohMgAqL2mNL0Y1esrnMhBawfbheejECdDdwIV7xePZafqdrZvvst7/jOV Vh9J4k24J5g3OVJYT+qIM5eY9ckDbBisWXkm1H8HXnJ0BoaC9xC6ge8RAlFB632MhQPI bqqBrDVs11671tmXmtXEyZu9TDu2KHYKvn+pvDuH2+dlvGn6FNOJp4BDxhu8OCsTfXuc GqImZ97bG3el3WMUrz/1dFy/kyl1cRCEXgtz/DPKYOs4EW5eN9gP4fKiGxhk/6eGefC3 VAOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W3BmmXXy; 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 oz38-20020a1709077da600b0078a3ef9f092si13644179ejc.998.2022.11.01.09.31.37; Tue, 01 Nov 2022 09:32:02 -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=W3BmmXXy; 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 S230064AbiKAQUc (ORCPT + 99 others); Tue, 1 Nov 2022 12:20:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbiKAQU0 (ORCPT ); Tue, 1 Nov 2022 12:20:26 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 567D91C900 for ; Tue, 1 Nov 2022 09:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667319625; x=1698855625; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x3Sm1HIWJ0zDGafhuDEQGcNzrmUhCp8majAoJIH0MBM=; b=W3BmmXXyqWOI+8mSvOPSBYjnFpVempanh+kxEM6qfxfjyyLn3PkA3iGa +rEcWAEJ/Flgz3nPtlYJXh5SwYOQ+IK0gvRypfvnwX4lgrqwcgIGlsXPd 94dC9WkYdjmtCzt1cM+q4VXBGNOSnO+F2xnPY80ynP/2mlHB/eRP4L3ed o+6mJFQMhdL/rCFj5L8rjwyo2wZo9gvH4Jxtz73tUyQ41r/gnoA16ARRM zRu47pmcGF++nJPu54HRZVU3UyjTteLXgDv5ggcHcgaQaW7EKPAoxtpFU cXMm/JZ7cccB79U/3dE7UKBZzJ95LpMtTCQaFTmWKTLBZA2+SJM3Ebj5g g==; X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="309175948" X-IronPort-AV: E=Sophos;i="5.95,231,1661842800"; d="scan'208";a="309175948" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 09:19:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="628623933" X-IronPort-AV: E=Sophos;i="5.95,231,1661842800"; d="scan'208";a="628623933" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga007.jf.intel.com with ESMTP; 01 Nov 2022 09:19:39 -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 2A1GJa8C019884; Tue, 1 Nov 2022 16:19:38 GMT From: Alexander Lobakin To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: Alexander Lobakin , Jiri Slaby , "H. Peter Anvin" , "Peter Zijlstra (Intel)" , Tony Luck , Kees Cook , Masahiro Yamada , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] scripts/head-object-list: remove x86 from the list Date: Tue, 1 Nov 2022 17:15:29 +0100 Message-Id: <20221101161529.1634188-3-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221101161529.1634188-1-alexandr.lobakin@intel.com> References: <20221101161529.1634188-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1748312074462341124?= X-GMAIL-MSGID: =?utf-8?q?1748312074462341124?= 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. Tested-by: Jiri Slaby Signed-off-by: Alexander Lobakin --- 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