From patchwork Tue Feb 20 19:21:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 203772 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp616727dyc; Tue, 20 Feb 2024 11:22:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVWlXNcUYW/kvjEAeB+5WbtJY6gf/weKfbtjfNYMMpYCxA8o4kxIHOKxBEJ4Xhmhc/1EumjL5NAGo8DagJSxr8auPYy/Q== X-Google-Smtp-Source: AGHT+IE7RTkJMZ0cMdJxxBrWyPqX9dC3OTkr6XWf7gRzss3JASgGE4wkXsAIR1mo9Ftrz2xhmkpG X-Received: by 2002:a05:6214:4001:b0:68f:5ac3:8af3 with SMTP id kd1-20020a056214400100b0068f5ac38af3mr9391079qvb.22.1708456965698; Tue, 20 Feb 2024 11:22:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708456965; cv=pass; d=google.com; s=arc-20160816; b=UyHo4E2x3+iy43Pc0StBq1pkPzFZaO87lM4Dc4lxZFjLrUD0QYT59NhG9WFuQo0YkO iyme+FAEVkPE6B0R0qLTYiuEUQ/8aORLAh+i+ELHJGAsQqWX/AUVQE1hmXWik3Mqc1Aa dVfGPF9GHBfGMGTzfAoi1Ohzz8S7E0UPfpt7UDJG/m1r6thcqkQiv7eY6WAVJO1WGctS ngPbtqzZrmvq4z0snQ9f57Rsggz3f23z86SNSzdRz5tFqImxChh1VLNZnXi7Wv8Z8bd4 LxyCrmFai95s+QoELTzzPFO1np75DNTU6+YiGJm76D5VRcUP1xFBwN47SyxRlO3eHXio 1U4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ah2+kizpm1MHuuLA0gzHwJWSSIWURWYNeGGYOg4ToNY=; fh=Hj2i9kyhXwFKCeqfJV+RZ4kXJyhTL67vH99FeWlp5y4=; b=WNZsiJ6I28U2E1R6ty8Raa4QGHaM+e+7H10bv31gb62VJYubwEJ2KNYN6GNbnf1qV4 r1KSx46P7xUak7lZUIyf0KiN2wCFGFEnEyct12aYwn5b+G1Nq2aANsrzWD2TmhfFs8HK 3XmOqxq61ekzEpyfxcPdJKYdU0T6jTzqiLXh0gCV/X28GDVO6Y1/r8rxeTE3AKJpky63 GLZAEPphAppQ5ZwTIu9FHXIMRqWxfhpbqIHWB7TbP7dzRrCmdafMeFZW7/ixYT8pss95 yyflr+lGZja/BOGyxoms1UIhkwYLOLA2Vz/xnU+J0W9BtKkWAf+U6B2W8uI6tbJDo0+C SEiQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=u5hyRRlD; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73588-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73588-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a2-20020a056214062200b0068f041f354csi9002969qvx.498.2024.02.20.11.22.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 11:22:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73588-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=u5hyRRlD; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73588-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73588-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6EF131C21819 for ; Tue, 20 Feb 2024 19:22:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9F8114AD00; Tue, 20 Feb 2024 19:22:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="u5hyRRlD" Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3621414A0B2 for ; Tue, 20 Feb 2024 19:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456924; cv=none; b=rN+FLP40pGklrsSx/HiY7cd9cDREgaIya5GQKprmVmffAN6nbpI2WonzVNT2FV2vmx9abJuGbnRYfy32oSiq2F2pQc3s4GPfcbeS9D7KO5qotMREoVn+lkKkPzy5n0oQv6vuzUi6UJn1BDgo/JE7GKLNHVg0KIlM6QaRwngsZnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456924; c=relaxed/simple; bh=37+UeHfbaDdGookO0QGGmnoCJCoWAfLqrxDYxUd6jj0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OeCnCRFpD9p863NgpEfOYjFEsHgZsZ0wgGWm7dyKAP7dTPOVLmHlrX0c7LWMKA/2P3j7JeHhc7BUB40Bnj5OLNdAEMQRyrHiflQ9r6IrDmVhpBgAtqkitdb69E/IfcO+mZzbdA/MqoFWWMjX2ILcNqNPXKCsjo9cQ7BGqWjB64M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=u5hyRRlD; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4126df1e7bbso12955e9.0 for ; Tue, 20 Feb 2024 11:22:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708456920; x=1709061720; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ah2+kizpm1MHuuLA0gzHwJWSSIWURWYNeGGYOg4ToNY=; b=u5hyRRlDJ5tTD41TlVL/eEcLdqhBVkcXd/nFbviYoXj/o1PCW0bVBzyBFf/nhy4sIR EVZPHE2Q+B8lopTWJpmZ4PKn0JzN0w4W/+Gcd6kZkY01kSplbmxeux3yvXzGtOiYmbim 0LRuNTLVf4ETg9hQgGaVKlOZf7YhJkDqL7jMV2ekX88nHl98zCLrYnNEqb6biKHB3iJT w4FnowJhKEuPyK+NQvV9Cyrs8Fkpsd4Y0nbR7oBja/PjBbUOI5UlL4rsd1uoMYTV8RwH rDnoT05vi9xH/nD0cJQaO+6Ug5xWXLfRcEeIPMcxEYrKQOqfikVBl62zyvJj6WPu6IAU wDug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708456920; x=1709061720; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ah2+kizpm1MHuuLA0gzHwJWSSIWURWYNeGGYOg4ToNY=; b=WMneCUq3QIMe7cFPD4JDhYIMdXU64tWi+Ws2Av413dumy5nvJ5ekParDJhTsL8up5M 9BVO4f2WskW7WoK/PtR47yrPZZuhMyYqLTnyFhB0S7/bmZ8zjJi6UbYFtwzA3bNeoWsm ojdTVQ7nt8pbKYRdGKMOGLO6Oobynf0itYAcSJUGOyCt/mqXucUsdTZVDdQNTQpb+JLX JxNoYOFlE+CJV0MdVMyN9hCmtth+XIZkwWgusBGCWHrzEnjj8aTvv2GE5r5cHrKwEYsK IHaGWZt+1fz/nIz+MHea99+HK9qcOR9oB5B3Gp8Wvwe41xwqxGZon5nKGtenkPfW/1q2 ZbAg== X-Forwarded-Encrypted: i=1; AJvYcCV1LAiHkAkKyNyQ+SsgDFshye5MJRu6CIVQW02j0eSBxfC6qyW4WqL/yxLbDOunYqSm8wKw6bHU7s22ASkhKZSMjgccsAbmBz+JHbkr X-Gm-Message-State: AOJu0YwqVy5brmC0B+/fFV5HRSb2ko+xwaRvJB8TjyPpeZO9+i4L3Pyu nxH8D9ApJJV6I95dXp63UjJS/N8GOEyCJQxljRxOifyhx743XLCCME0J1CN4Nw== X-Received: by 2002:a05:600c:600f:b0:412:6d66:81d8 with SMTP id az15-20020a05600c600f00b004126d6681d8mr10163wmb.7.1708456920465; Tue, 20 Feb 2024 11:22:00 -0800 (PST) Received: from localhost ([2a02:168:96c5:1:cba0:1b55:6833:859e]) by smtp.gmail.com with ESMTPSA id y17-20020a05600c365100b004126101915esm4500wmq.4.2024.02.20.11.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 11:22:00 -0800 (PST) From: Jann Horn To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, Kees Cook , Jann Horn Subject: [PATCH 2/3] x86/boot: avoid recompiling misc.c for incremental rebuilds Date: Tue, 20 Feb 2024 20:21:43 +0100 Message-ID: <20240220192144.2050167-3-jannh@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240220192144.2050167-1-jannh@google.com> References: <20240220192144.2050167-1-jannh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791446971206274900 X-GMAIL-MSGID: 1791446971206274900 Currently, we rebuild misc.c on every incremental compilation because the generated header voffset.h (containing kernel image offsets) changes on every build. Turn the three macros we need from that header into external variables that we can separately store in another C file. Signed-off-by: Jann Horn --- arch/x86/boot/compressed/Makefile | 4 ++-- arch/x86/boot/compressed/dynamic_vars.c | 9 +++++++++ arch/x86/boot/compressed/dynamic_vars.h | 11 +++++++++++ arch/x86/boot/compressed/misc.c | 6 ++---- 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 arch/x86/boot/compressed/dynamic_vars.c create mode 100644 arch/x86/boot/compressed/dynamic_vars.h diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index f19c038409aa..d18a553c16fa 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -94,11 +94,11 @@ targets += ../voffset.h $(obj)/../voffset.h: vmlinux FORCE $(call if_changed,voffset) -$(obj)/misc.o: $(obj)/../voffset.h +$(obj)/dynamic_vars.o: $(obj)/../voffset.h vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o \ $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \ - $(obj)/piggy.o $(obj)/cpuflags.o + $(obj)/piggy.o $(obj)/cpuflags.o $(obj)/dynamic_vars.o vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o diff --git a/arch/x86/boot/compressed/dynamic_vars.c b/arch/x86/boot/compressed/dynamic_vars.c new file mode 100644 index 000000000000..cda64ff4b6da --- /dev/null +++ b/arch/x86/boot/compressed/dynamic_vars.c @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include "dynamic_vars.h" +#include "../voffset.h" + +const unsigned long vo__text = VO__text; +const unsigned long vo___bss_start = VO___bss_start; +const unsigned long vo__end = VO__end; +const unsigned long kernel_total_size = VO__end - VO__text; diff --git a/arch/x86/boot/compressed/dynamic_vars.h b/arch/x86/boot/compressed/dynamic_vars.h new file mode 100644 index 000000000000..a0f7dc359cb6 --- /dev/null +++ b/arch/x86/boot/compressed/dynamic_vars.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * This header defines some variables that change on every compilation and are + * stored separately in the small file dynamic-vars.c, so that we can avoid + * rebuilding some of the other C files in this directory on every incremental + * rebuild. + */ + +/* Variables containing VO__text, VO___bss_start, VO__end */ +extern const unsigned long vo__text, vo___bss_start, vo__end; +extern const unsigned long kernel_total_size; diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index b99e08e6815b..ff13cc3e703d 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -15,8 +15,8 @@ #include "misc.h" #include "error.h" #include "pgtable.h" +#include "dynamic_vars.h" #include "../string.h" -#include "../voffset.h" #include /* @@ -188,7 +188,7 @@ static void handle_relocations(void *output, unsigned long output_len, int *reloc; unsigned long delta, map, ptr; unsigned long min_addr = (unsigned long)output; - unsigned long max_addr = min_addr + (VO___bss_start - VO__text); + unsigned long max_addr = min_addr + (vo___bss_start - vo__text); /* * Calculate the delta between where vmlinux was linked to load @@ -330,8 +330,6 @@ static size_t parse_elf(void *output) return ehdr.e_entry - LOAD_PHYSICAL_ADDR; } -const unsigned long kernel_total_size = VO__end - VO__text; - static u8 boot_heap[BOOT_HEAP_SIZE] __aligned(4); extern unsigned char input_data[];