From patchwork Mon Jan 22 09:08:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 189982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2452902dyb; Mon, 22 Jan 2024 01:13:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwHPp9pHRNC+unwA8ko48ViBvx+rA5IvS8b7e8f5AAWIHXYDWscWQGRhc0+ZoFSTtcrPn/ X-Received: by 2002:a05:622a:4c:b0:42a:4456:15b0 with SMTP id y12-20020a05622a004c00b0042a445615b0mr437151qtw.36.1705914804860; Mon, 22 Jan 2024 01:13:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705914804; cv=pass; d=google.com; s=arc-20160816; b=IVHa3l5KAr2jcd9PD1jD8POjKrgWhZG/6XzCwNhkmXcT91iX0rucQft2F0Cxuz1vdE /NyFXL5fWHABZgMPMt92/Fz8hkNmYDk0g7yvwHa1NqFU8EOnSULBa+AYTpiExxpPWiaw wq6Jeqy0IFbS0upV8WzOgwYMdh46xgcika++QfnTBSmgQpfez2z2I79Hw5qyKhqFeTnu 2g+xti74MQ3BxSTHYfDqu5dedJBoCf/zJ7gqz90haLrzKLcFSkY3XujPIhAHg9zXA6d+ xYVK2rV/IR+HCoNRJzvTWpZBvGSU00P0YXi8V2rQNaKr7x8s66k5RXf35QsZhjcwJ30J 40Bw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=0Ue2vmRkHm0fVc6V6NYaJ8ToLI0DQfe3Y1iY9J4coyg=; fh=5AiHdFowod8yCNdy/id3xiSSfKdDCkZYEkI53gyaq68=; b=0W2NJqusSr5wUmUZF1ZUBvbxGvm/o269s5lbOCCgdGKh3vXEnByW7dnl7L3jWhXLtG xT8xp+QFErX6Pcl/z4fd3HVok/u4Vs/vQCty6eXuRVKouoUsuqGL5IJDizlfbHsaZgNs LmEOWJDbfVt04hei4qVKNH06EJTarAgkLT+KO9C11GWd89/pp2khdjUhD7dQauy0GZPe s5Anx2IERud6UrUjx9XawPxmcKyEAf6WrZ+Ao1Wvm1D4UMdiFL5AVvHSh2X2TlLBtEkU Vvtvpd1HJ3XHPoHYJ6xYF5g+NQ/H7IJx0TzIP64e3BLcNDOu9SJ7mW9UPzBYRfhEXOJ7 pfyw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SG6i9JSp; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-32599-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32599-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 p13-20020a05622a048d00b0042a3090e7fasi4660325qtx.683.2024.01.22.01.13.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 01:13:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32599-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=SG6i9JSp; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-32599-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32599-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 97B191C24270 for ; Mon, 22 Jan 2024 09:13:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A384439FCB; Mon, 22 Jan 2024 09:12:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SG6i9JSp" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 797FA39860 for ; Mon, 22 Jan 2024 09:12:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705914768; cv=none; b=XUTbtJW2FJJDSm0fDHr5j3kfhhzYxFrnKz8uiPBRPhahPvvAyVtSFP6d8rhbU3TaBGuQ8HqwwT+Y8sPvsoVxe0jd49iJX+JiPR7pfPRuYoqhC5ussDspfMj8CUDYJvexgTa1C7CJlfuxti/C+FGymFoUhnFUZ+Mj6VlL7Q2qcsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705914768; c=relaxed/simple; bh=NvZ9QYXHyD9CvB6BGA5UKBh+CJlv7ohKGlZB0ViTzZ4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=vDyl7lakLiVkDiHSTIY9U4v8kbBb5CR9LgIwlyFDRt9be0zfWVp+Is9ISUBdTg0s3OBwwbbkyWuMKNDQSP+Cn8Vt3JRG37/qJi76UglLIuMpV46+Pbib6dOstUL3ysztRDw5AJHuuX8a4edmvE9fgJ/SFU30Jb02Qh9/KsqyZf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SG6i9JSp; arc=none smtp.client-ip=209.85.219.202 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=flex--ardb.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc237543b74so3348656276.2 for ; Mon, 22 Jan 2024 01:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705914765; x=1706519565; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0Ue2vmRkHm0fVc6V6NYaJ8ToLI0DQfe3Y1iY9J4coyg=; b=SG6i9JSpVNdDkPcVZQkC/nQclGrDc5CAbladqHJL+t4v3HiQDAHtFiGRuoHF6fo2ss rW6XcRNyFJ6wB4S4HkYqFLmbJEAHQ07qAcEFsYBVDUNceVFoT36ilXncUOBGmt+9IJvz B3GNOmzvUkYPx3P7k8M55NqlcrU8Q7aZWZyB63YnNUkJZYy4ucrb+cEbOiQAO6rXfYvc 4N4aKLL5BFr9gt0MPMHmhuC2wbT7WuXOcm6gSvXY/dYyQTT3qybvimFbEbl/7D6v/QTs JBtCp2lxahkwcSA0qn055qk+OcaW8DX+BKVZPtv5jzPAKP/+j5H0pxuwIxxEG5Fy48um trig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705914765; x=1706519565; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0Ue2vmRkHm0fVc6V6NYaJ8ToLI0DQfe3Y1iY9J4coyg=; b=ISc9EyMf2M+KmuDggwWfmMxOXtnx/EFGn9HuLfn7AmTTLYISANqCMWp4bP3XL6b2cV URZyzAgw4KRI+jOQIJJRrzhr5r50+YK6py4HlC4RQCjBOtTG5U4RNV9xI0pYqbbVDUAU Ncm6qVHavMSCcwzg0v8j95vwRtDlefe0fERX4GY2UNdmQS1ihE86Anrvf/bbTrFZ0dk+ V91AlsbNd9/B9TkEFt9C+GUMY/pO4Hzd02BrrVriEcsBoFkgqEdnyQZkUElSd43SIuxV jiJEthdIVqERebxyYeJ1CPDW+HboCEwowIGSR5l/2hcZeO48yIT9Iw5r2ILpfTTgqu+v /PyQ== X-Gm-Message-State: AOJu0YxNTfM2kPSDVpOlEG/RT6yx/R2Qr6PQFu7pABDl9CQNp/ritbyu HlA8JRWHQWreOJtX3KHzn4Sos9plgbvDn7trsE3CnburOBOXp6premgMHtYDzghnJOKuTSL434h wXUzqbEJNgUxImCH1YZrwemLgM+k6XoW7kNCQUmqXxkaMjJA2FEjn3qQbgPyKTxK3bf+klSjjJ6 2LLSHPEHrxsOr0MpI5end8QOmqBfhObA== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a25:11c1:0:b0:dc2:46cd:eee9 with SMTP id 184-20020a2511c1000000b00dc246cdeee9mr238812ybr.4.1705914765393; Mon, 22 Jan 2024 01:12:45 -0800 (PST) Date: Mon, 22 Jan 2024 10:08:53 +0100 In-Reply-To: <20240122090851.851120-7-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240122090851.851120-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5349; i=ardb@kernel.org; h=from:subject; bh=8Z7gd3kTb2u9hK0wTWYrEf9GDcgvcakQPNv0R7gN2o8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXWdwdIsmzezFAp52a+9FVjSY79C54j1MiVvl2f/V+7/G aRm/e9hRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZiIeAfDf48/O7a+4GRIKPuy hm/X71tsG+701bE6Fof27rFf/Lzz7E+Gv+Jm0Z3bW9gd+bzVvy3/bZN5q07v2ZbXOzgzH2kK7Fj 9jBEA X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240122090851.851120-8-ardb+git@google.com> Subject: [RFC PATCH 1/5] kallsyms: Avoid weak references for kallsyms symbols From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Martin KaFai Lau , Nathan Chancellor , Nick Desaulniers , Justin Stitt , linux-arch@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev, Kees Cook X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788781322552062251 X-GMAIL-MSGID: 1788781322552062251 From: Ard Biesheuvel kallsyms is a directory of all the symbols in the vmlinux binary, and so creating it is somewhat of a chicken-and-egg problem, as its non-zero size affects the layout of the binary, and therefore the values of the symbols. For this reason, the kernel is linked more than once, and the first pass does not include any kallsyms data at all. For the linker to accept this, the symbol declarations describing the kallsyms metadata are emitted as having weak linkage, so they can remain unsatisfied. During the subsequent passes, the weak references are satisfied by the kallsyms metadata that was constructed based on information gathered from the preceding passes. Weak references lead to somewhat worse codegen, because taking their address may need to produce NULL (if the reference was unsatisfied), and this is not usually supported by RIP or PC relative symbol references. Given that these references are ultimately always satisfied in the final link, let's drop the weak annotation, and instead, provide fallback definitions in the linker script that are only emitted if an unsatisfied reference exists. While at it, drop the FRV specific annotation that these symbols reside in .rodata - FRV is long gone. Tested-by: Nick Desaulniers # Boot Reviewed-by: Nick Desaulniers Reviewed-by: Kees Cook Link: https://lkml.kernel.org/r/20230504174320.3930345-1-ardb%40kernel.org Signed-off-by: Ard Biesheuvel --- include/asm-generic/vmlinux.lds.h | 19 +++++++++++++ kernel/kallsyms.c | 6 ---- kernel/kallsyms_internal.h | 30 ++++++++------------ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 5dd3a61d673d..a39e050416c7 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -448,11 +448,30 @@ #endif #endif +/* + * Some symbol definitions will not exist yet during the first pass of the + * link, but are guaranteed to exist in the final link. Provide preliminary + * definitions that will be superseded in the final link to avoid having to + * rely on weak external linkage, which requires a GOT when used in position + * independent code. + */ +#define PRELIMINARY_SYMBOL_DEFINITIONS \ + PROVIDE(kallsyms_addresses = .); \ + PROVIDE(kallsyms_offsets = .); \ + PROVIDE(kallsyms_names = .); \ + PROVIDE(kallsyms_num_syms = .); \ + PROVIDE(kallsyms_relative_base = .); \ + PROVIDE(kallsyms_token_table = .); \ + PROVIDE(kallsyms_token_index = .); \ + PROVIDE(kallsyms_markers = .); \ + PROVIDE(kallsyms_seqs_of_names = .); + /* * Read only Data */ #define RO_DATA(align) \ . = ALIGN((align)); \ + PRELIMINARY_SYMBOL_DEFINITIONS \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ __start_rodata = .; \ *(.rodata) *(.rodata.*) \ diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 18edd57b5fe8..22ea19a36e6e 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -325,12 +325,6 @@ static unsigned long get_symbol_pos(unsigned long addr, unsigned long symbol_start = 0, symbol_end = 0; unsigned long i, low, high, mid; - /* This kernel should never had been booted. */ - if (!IS_ENABLED(CONFIG_KALLSYMS_BASE_RELATIVE)) - BUG_ON(!kallsyms_addresses); - else - BUG_ON(!kallsyms_offsets); - /* Do a binary search on the sorted kallsyms_addresses array. */ low = 0; high = kallsyms_num_syms; diff --git a/kernel/kallsyms_internal.h b/kernel/kallsyms_internal.h index 27fabdcc40f5..85480274fc8f 100644 --- a/kernel/kallsyms_internal.h +++ b/kernel/kallsyms_internal.h @@ -5,27 +5,21 @@ #include /* - * These will be re-linked against their real values - * during the second link stage. + * These will be re-linked against their real values during the second link + * stage. Preliminary values must be provided in the linker script using the + * PROVIDE() directive so that the first link stage can complete successfully. */ -extern const unsigned long kallsyms_addresses[] __weak; -extern const int kallsyms_offsets[] __weak; -extern const u8 kallsyms_names[] __weak; +extern const unsigned long kallsyms_addresses[]; +extern const int kallsyms_offsets[]; +extern const u8 kallsyms_names[]; -/* - * Tell the compiler that the count isn't in the small data section if the arch - * has one (eg: FRV). - */ -extern const unsigned int kallsyms_num_syms -__section(".rodata") __attribute__((weak)); - -extern const unsigned long kallsyms_relative_base -__section(".rodata") __attribute__((weak)); +extern const unsigned int kallsyms_num_syms; +extern const unsigned long kallsyms_relative_base; -extern const char kallsyms_token_table[] __weak; -extern const u16 kallsyms_token_index[] __weak; +extern const char kallsyms_token_table[]; +extern const u16 kallsyms_token_index[]; -extern const unsigned int kallsyms_markers[] __weak; -extern const u8 kallsyms_seqs_of_names[] __weak; +extern const unsigned int kallsyms_markers[]; +extern const u8 kallsyms_seqs_of_names[]; #endif // LINUX_KALLSYMS_INTERNAL_H_ From patchwork Mon Jan 22 09:08:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 189985 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2453297dyb; Mon, 22 Jan 2024 01:14:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJO79OZB+rOVxuuiTZgM2LfeYpQmO35vTTsg6dbELMOTK6/Ef7Rjmxoqv8bv+lvTddr7/C X-Received: by 2002:a17:903:41cf:b0:1d7:31fb:87e4 with SMTP id u15-20020a17090341cf00b001d731fb87e4mr4592501ple.44.1705914852930; Mon, 22 Jan 2024 01:14:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705914852; cv=pass; d=google.com; s=arc-20160816; b=LirZunTr5HHBkapxykhsWd36O+gDqRjfj0y9NFXeudHq88IGk1zPemKAIcdT0JfokR 7gg13MdRBuqKH15W/v5eNoGyo9oIthNlP1s/QsZKDwp3B2jijs33pmEjXopwWNFPnvRP v5+30vj72mGijtfnrpEQvQhdwzZMLq8kU40sLT+Be3H13kYM6wX0oeRf5Yu/FTkx2xUa 2W0z4dUvV9J2NWq+cupQMvis1HqlPNzldr4hLWnuGXgpAnwsW+J4Eh0fMAXtWwIQLfF/ w5+2tCmY3aTdz2qmqKsbTj888kBy6Wct/bAxkPsWcs+hPUPck5+GPEDyXiLUymroXKgO eSEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=6+ATsTLfC/nfRiaNDc88cmvgZOlK0W3C+DyqDLNAS68=; fh=48HUvOMbKpeHraf1klkRburnyvYvg0IkDo40jTOEaFs=; b=XsRwBYth8meiBfOx8kGU9Fv2Sq/v4nMt4KgwstEpenfDyhxnHeEoercsuM+COeczRU oUEIukBzx5HXtGtgiFnDlbXseAJQBZbmfdO20Hf0VW/1ihbnCk/6Wwi8owch4yl51vxH GZZET/46sBnSgHwSDd7mRQlRPE4X7c/Al/ycbuM546N6RBeK5S0zmC5gcLpWk2gPfZrg nbEnKll4b+WqFs5Kk2/Ni+92bp/TV88nMip6c2gQ/rhEUMPgLxwylSLYqdyeaMwiCgJW DHZwgLYdz5Q+cQkYJOoChZt6PN38FTY/RrDpn0UXI9Iy0yH7ET9khoTYXJ9FTDRrQ0E2 cFLA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1ZnG2EjT; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-32600-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32600-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s20-20020a170902989400b001d7271c0988si4744556plp.569.2024.01.22.01.14.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 01:14:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32600-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1ZnG2EjT; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-32600-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32600-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E9573288E90 for ; Mon, 22 Jan 2024 09:13:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 535FB39FEC; Mon, 22 Jan 2024 09:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1ZnG2EjT" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 F023039AE0 for ; Mon, 22 Jan 2024 09:12:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705914770; cv=none; b=dofZVbxo+WJ5roWPaGcoV1hSbha2YqgA5dRmWLpMeR0RN8pO9ixgPyVtk/mgQ+9b4YHU0PhYNNCE+3jrTXpKuMxiYHP1Ffo02qzw3wtp/h4CVkhxOwKZMY+h/Mw6uk64hrOeSvVC5iLyIKnZl6CFGP5yxxXw3NnATsVWxtiu8SU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705914770; c=relaxed/simple; bh=FI1bdkhRdpG4w1m18XkG1rAosi5jGY3arzDb2dniOFM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qK+5fhDv6BDnM9EXTpOCq8ScIme4WPZTDJfRYEppVtsquABwrlmCUQPUlkrJVACUe9yJWVmsjIGbRsMzkcmb0LA8X++ALwF2aXoh6fWXruhHQp+thGqcZ/ZcxiF0Vgb2jgAR9UJTcHQcrCOm0kXYOiDhwyyABO+f+xHgIAZiHQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1ZnG2EjT; arc=none smtp.client-ip=209.85.128.202 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=flex--ardb.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5ffc7ce3343so14576167b3.1 for ; Mon, 22 Jan 2024 01:12:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705914768; x=1706519568; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6+ATsTLfC/nfRiaNDc88cmvgZOlK0W3C+DyqDLNAS68=; b=1ZnG2EjTI+CD842FcsXQHt+IW5QVFeTgYzgP2WWYptU4Hbc/fwy21rdskldIgg7Pq1 Kkow+KRBA+0nR6ZkwaxxIHF+eA/xc7IErup5nNfsGOuy0uoWvM6viU5VgMjeCe40la/S Ldp6MpfJgupK9BDZuZJ/589iGavTh/E9+SrC2dbQNsuCOlnuRu35c00qA5ZUzubuE9yf ZNo6WYMT0h8imxAN+wg4OtCi3Sl+3G6CSkTIlyS5FJBSZ8XdV4hnLEk/6MyzazstSG5w Cid9dA/yRFrhAIvRuFPHwuzKin/bGVy0/d7JhZ48dEDajYf9hfomG8lIlrBz3AyGsSlO 91RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705914768; x=1706519568; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6+ATsTLfC/nfRiaNDc88cmvgZOlK0W3C+DyqDLNAS68=; b=osEsYJc+bgBYMqm2pWBeNA7zymFYFkujzbXITd3x71y3R2bBDJzusNkUGQU9t/zgVV Y/mOEWGfKya/ff0Oh0QMXIAb71wRnAR3Bio3X3qif1dIsuue0KMSPup4BxWNiKR/F74Q I5ZdeynvirH0RGxN+1p8crIjpx+7V7LRS2bVeGAFCE9a2aIYudgCc55ffXEe+z6d4i98 GvWgE0vp9KLUbTTx0lssHnMZi1mtpMsBSb/5QCyzwm8HT+W2X/5GWP2su+2nVnUaybnp AF/tQJJcHiKAAVGgtFBxwpjE64wngv65rOEgFfWbkpFzH4xcaSBvl150JEe/i/knEDFi vE2A== X-Gm-Message-State: AOJu0YwWR6EY0DhK6f4Pa+UuG3C8m7s6HIg5G29gXI5L2jAxzbttPWer ZGGPwF8NN4hKVn46tYqE1Qb/XWrpzWXDeun401yInYPYYcrI6ZiijumWRkwJg3rxWVagJZSeOiU GjBNHDsOseav2KrZ1Bk+lTqmOQcVoxm3lgdHjPL0TMq/pGvH59//kWpMeDVnQ163exXosxhibPI lkHgBDJLt2Ug5Nilxwxgq7IMsGAmZFPg== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a81:5753:0:b0:5fb:7e5b:b877 with SMTP id l80-20020a815753000000b005fb7e5bb877mr1288192ywb.7.1705914767726; Mon, 22 Jan 2024 01:12:47 -0800 (PST) Date: Mon, 22 Jan 2024 10:08:54 +0100 In-Reply-To: <20240122090851.851120-7-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240122090851.851120-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1618; i=ardb@kernel.org; h=from:subject; bh=A4glY9lFGh3ZCS2BolwbxkiHAY08LMb32QJUAkFZOD4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXWdwbIambt6UbumlW3o3fUnes5Ggxs7A9m5dyfPXsn/d JVi3k3njlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjAR7l2MDFurHzxqXGW4W4t3 ia3/+5v/H5kWi8SUzC64/r7UO4X93XqGX8w7t6fEqAq8Lsi/1jt580dBlTI521k3p5SKLZda6x5 VwAcA X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240122090851.851120-9-ardb+git@google.com> Subject: [RFC PATCH 2/5] vmlinux: Avoid weak reference to notes section From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Martin KaFai Lau , Nathan Chancellor , Nick Desaulniers , Justin Stitt , linux-arch@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788781372878585575 X-GMAIL-MSGID: 1788781372878585575 From: Ard Biesheuvel Weak references are references that are permitted to remain unsatisfied in the final link. This means they cannot be implemented using place relative relocations, resulting in GOT entries when using position independent code generation. The notes section should always exist, so the weak annotations can be omitted. Signed-off-by: Ard Biesheuvel --- kernel/ksysfs.c | 4 ++-- lib/buildid.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c index 1d4bc493b2f4..347beb763c59 100644 --- a/kernel/ksysfs.c +++ b/kernel/ksysfs.c @@ -226,8 +226,8 @@ KERNEL_ATTR_RW(rcu_normal); /* * Make /sys/kernel/notes give the raw contents of our kernel .notes section. */ -extern const void __start_notes __weak; -extern const void __stop_notes __weak; +extern const void __start_notes; +extern const void __stop_notes; #define notes_size (&__stop_notes - &__start_notes) static ssize_t notes_read(struct file *filp, struct kobject *kobj, diff --git a/lib/buildid.c b/lib/buildid.c index e3a7acdeef0e..15109fe191ae 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -182,8 +182,8 @@ unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX] __ro_after_init; */ void __init init_vmlinux_build_id(void) { - extern const void __start_notes __weak; - extern const void __stop_notes __weak; + extern const void __start_notes; + extern const void __stop_notes; unsigned int size = &__stop_notes - &__start_notes; build_id_parse_buf(&__start_notes, vmlinux_build_id, size); From patchwork Mon Jan 22 09:08:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 189983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2453068dyb; Mon, 22 Jan 2024 01:13:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGufLZ2gPVz37PclYdBwe6vDe8p/sRDy00HAibqDIj/sHYoGPJGGXUrx1gAb5RnwxaLIZU X-Received: by 2002:a05:620a:2181:b0:783:8e25:735 with SMTP id g1-20020a05620a218100b007838e250735mr4606016qka.155.1705914827897; Mon, 22 Jan 2024 01:13:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705914827; cv=pass; d=google.com; s=arc-20160816; b=L5HGl9ovOtNqOXWByF2ELMja/+TvIg6T3C5F5ukJjVzgQKHjRLnjWqCgWF1w1Qrsfl 9zpefr2XqjMNbNpeXzOMznZune5GZ1x7KhCC2W8g4BIj0gfdx89rqO+bJkUzJtQyXwML I9dh5OE4EcaSo1dRClwQAzUk3xj4BvncjZTy+AlDsvKqWLucZHFoJEduBXQSSFAHbade PkwG/FZfhQinIicO5JAf6SEsBhnrlX46MLtAB5sfLFLCesCamQy93//045jdbIV6aiKr B63sMEcSQGvJpAneY98PTXmTnAAQbPxSdFttK1IDP0BEG5CneHW94DbNRPTsPNKImpBI aHTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=anpwjJFJvKmui4DbRVFl+bq/czyO2Fw5IsMP2KX6EWQ=; fh=48HUvOMbKpeHraf1klkRburnyvYvg0IkDo40jTOEaFs=; b=Rn0lltVPKT962ZOj93ZxLFEl84xLaw35L3qpXxjV8UwusaRoi9qGC7ageJF1Ae6bif ySbx1DFqIrm+y15t6Ba5OSSNinh+/yj4sMa3YzTx5pqT4rhUtK5wWjtp5NUZu0WqPEGz /xmfsC26KYLFnzQgan5HOpwDY8XUvCS0y3x7GCT+wPgDElQ5AFx2s9zushvvZTnrpLBX J6suHElxp3j/kbuIqdaQwMpc4icwu1VI/n1uD2a7Hoqs9hlNCr0jNVlrBEKvu/mH9syB V/PuTHsXb/vylg7k2ye+ekKw+t+G7hKyV00HIV89+QVnCjLC7PePcIMo8DgY3aiPL0sG /8Rg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jLmcULa1; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-32601-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32601-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 l10-20020a05620a210a00b0078333a213cdsi5068428qkl.368.2024.01.22.01.13.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 01:13:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32601-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=jLmcULa1; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-32601-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32601-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 ADB171C23D0B for ; Mon, 22 Jan 2024 09:13:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 511C03A1A6; Mon, 22 Jan 2024 09:12:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jLmcULa1" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 1A45239852 for ; Mon, 22 Jan 2024 09:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705914772; cv=none; b=nsBnguFs3XL5Pne+puROHYqiQGJkw5fRnmepV2lhch2a+rVHHzMIDi0O4k7wlcFIZNMxn3WTc3A+XYYSvYDYAg0gIhg2DBsovR7iKvR1Cr8ogW0lG2mXYAX8V3EIdqY7AKKu6DHh1uddfXI9INVojvqBJKMmOmHw/XJPxcqSNDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705914772; c=relaxed/simple; bh=7WqvfI2V9xt/Od2Zwwt1owQ25hJdvvX/uuPnR9lgy1Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AVmzjKWJPlwnOleqBPIKjEG2lD5QBoC0wPKtg21YyaA/yAehLjcunkSTFtjnZZZrBfEwZf+raSaPNy4QYbNVRTYXHXW8XCPlGOwBC0EFMqnVJThLzxO8jky8cqZ4Ppg+wdIHAsCluZ5imlY9Y8QMaOU/HRrYaciZgMPJsNpmrxQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jLmcULa1; arc=none smtp.client-ip=209.85.219.202 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=flex--ardb.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbe9dacc912so3473093276.2 for ; Mon, 22 Jan 2024 01:12:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705914770; x=1706519570; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=anpwjJFJvKmui4DbRVFl+bq/czyO2Fw5IsMP2KX6EWQ=; b=jLmcULa1WyQQmLpq+xiWSpwC4o/CGgXinM1ss1d9caPF2VERjWmSGEpW2QB+S9PBBn AdzGNiMS7rOxsekj2iRm+BXlDHvdRxfiwR1P7JR5gBzkC8YUsXuME8svP7Zn/dyg/U/k 0s+X3BNQyQCW6EEoZjd9S9Wsk3Kv2orP3IdXVWJ+RS0N2eCg+OySHK0MbjsjUheKOxfq lf0ULmV8tXBpZ/p/pYGwqk2A+3vp5S50erpiHKQItMYQKksz2/TeTTYzyzeU3bdsJCYC Kf6Nwco7FcKxOBa6DYUZs/n1BxgsM3om31rgI5caY0HbKPkfJvJ+WRFgTIjfiZ3E64WU Jl4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705914770; x=1706519570; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=anpwjJFJvKmui4DbRVFl+bq/czyO2Fw5IsMP2KX6EWQ=; b=hv854aYOMJwXQCAjwq/0/XHRpdtxF77eUi6bXYCi3rb1ePmC7zAKe9w0ZuaD9SlHmh +vEMaplgMlKmdowzEfbQ2nvIiLmmo5XiWQ1f9FfI4ypvAwHivxMey7Z4X/frQvtXltVq EopNxUqSw5wP8ZZ6tw2bSwE3MiBw/rjqzr8iGakLxm4jB1VDF2aQoOS3aaq5+0RBoEj4 tjBl305jE7gSqbUA3+e9rzISuV4Ew3iTBJjU+cIieU9jKvQtYRcFkuri7WY7HO0VtfH7 5ieV4KFzTxVmbK71QCTSL2p3l4JgYWiqvxWZRhKFIsIQ69dNVCBDA60GHSnHGRxA+kCm 5WAA== X-Gm-Message-State: AOJu0YwXpjkI/Ti7LT/kc9LxXtOtHl827pf/H2W+Em+umCEzsSGWq/Tl E7llfI1Aha/dHyJ2NqobWyinjq+a/BQx55A2obLP2IE5vPEctUhKLOaIMn1GdI2J8lECbH5rwnC +Od6VkuEJ36PO68lp+nXrs7MEwd9Yus7Q5UjZUlfShwZr/jQ2m1S4H2xuaPDz4CzMKsI4oTGRfh n7xx23YtcIbyTpgRVzsmrPs3SulSJafQ== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:1808:b0:dc2:3426:c9ee with SMTP id cf8-20020a056902180800b00dc23426c9eemr240839ybb.11.1705914769920; Mon, 22 Jan 2024 01:12:49 -0800 (PST) Date: Mon, 22 Jan 2024 10:08:55 +0100 In-Reply-To: <20240122090851.851120-7-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240122090851.851120-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1581; i=ardb@kernel.org; h=from:subject; bh=thQkn6eFYWU4rIO38nRY5rSfaRiPUJPmqajniqH14XU=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXWdwXL25bMmmm1ZFF9evWDmkTcTIha1sGp3zPaal+6zr 4qB+1xVRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjIGztGhtPFZyb/Xb5FN/f7 90CdRWd52mdPLC3t2LdyTaY67xfrJysZ/gpIeM4/a/g0Y3fTyS5Nqasbk9+o34rxme419eRVjen fGRkA X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240122090851.851120-10-ardb+git@google.com> Subject: [RFC PATCH 3/5] btf: Avoid weak external references From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Martin KaFai Lau , Nathan Chancellor , Nick Desaulniers , Justin Stitt , linux-arch@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788781346833921029 X-GMAIL-MSGID: 1788781346833921029 From: Ard Biesheuvel If the BTF code is enabled in the build configuration, the start/stop BTF markers are guaranteed to exist in the final link but not during the first linker pass. Avoid GOT based relocations to these markers in the final executable by providing preliminary definitions that will be used by the first linker pass, and superseded by the actual definitions in the subsequent ones. Signed-off-by: Ard Biesheuvel --- include/asm-generic/vmlinux.lds.h | 2 ++ kernel/bpf/btf.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index a39e050416c7..ef45331fb043 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -456,6 +456,8 @@ * independent code. */ #define PRELIMINARY_SYMBOL_DEFINITIONS \ + PROVIDE(__start_BTF = .); \ + PROVIDE(__stop_BTF = .); \ PROVIDE(kallsyms_addresses = .); \ PROVIDE(kallsyms_offsets = .); \ PROVIDE(kallsyms_names = .); \ diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 596471189176..a659fc7045bb 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -5581,8 +5581,8 @@ static struct btf *btf_parse(const union bpf_attr *attr, bpfptr_t uattr, u32 uat return ERR_PTR(err); } -extern char __weak __start_BTF[]; -extern char __weak __stop_BTF[]; +extern char __start_BTF[]; +extern char __stop_BTF[]; extern struct btf *btf_vmlinux; #define BPF_MAP_TYPE(_id, _ops) From patchwork Mon Jan 22 09:08:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 189987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2453376dyb; Mon, 22 Jan 2024 01:14:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+FMrVChi3knVbUl87LgI9yvLH62zcIVoXR+pGk6VdQmx+cix808tyEZqDEnPoEe5c0Gwt X-Received: by 2002:a05:620a:4249:b0:783:9d13:644 with SMTP id w9-20020a05620a424900b007839d130644mr2656616qko.28.1705914860251; Mon, 22 Jan 2024 01:14:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705914860; cv=pass; d=google.com; s=arc-20160816; b=bHwPWfJxiizHikyhXfni5mRc6gL2UgP6zO+O9GlCXytPFNmSvJo4huJ9dRtU8cEyNa hEMR7OQD6LpdWXMEvXckY1L3wBlRLtTgONNoGOusC04P07sGUBDQgOaEOchEBKwSDuHH JVxfUDkbm+6dqXCozwo0x6EvojHw+SrmciIGN9FPLe/GkuwrKobr/oqEGMlFPn20atIj UD9XIKyWAL0iQkXIT1e3mr0TPk9yqfTwgjGbmSvi2kYouFFb3K7/5xhwS008uVJZjrZD fDUIVU9q4P4Cc30o0/zfhPU/H/zFkBS/y/4Wj1vUlAZoUXv2jwgNXshPwKGZOsN3BObW 3ssg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=IfnnJzbo8UZ3onwnncaopOvG+BfrFgnNq0Hm48mm5EQ=; fh=48HUvOMbKpeHraf1klkRburnyvYvg0IkDo40jTOEaFs=; b=fmlLr2GQFdenez7LjxblPY8WRZMZz++mpYTKbe7Y/RGqwOlCsCuOvFqORRgj7t1bUm 3B/btBcWNK9Y/wl2kpw/QXaoD0uTp+sQ2smKU9BVdd4faJM4HnQju0c3SFjU4BLp/TNJ bKR6uGA1f948LBKAO2x+JkvjViJpZV8nU3LT8LV9DTj7rxODaYuWeyUQfLbmK0lkWD8J 7LtgUIveXGGKauiRBO/SMrtR8uwcSRWUyOfDLi5NVyixs/+b0DOAgy5Uh+wy78UoU3AX YMULMHBlTISBdylyq0Xqgxv4rZafntwI+JROPl4YHf75ay2yfdtZZ/O9TS0l3QOVTdkG +hRA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QSyIx2XL; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-32602-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32602-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 z6-20020a05620a100600b007813026ca37si5033402qkj.502.2024.01.22.01.14.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 01:14:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32602-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=QSyIx2XL; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-32602-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32602-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 AEA591C23E48 for ; Mon, 22 Jan 2024 09:14:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03A7B3A27B; Mon, 22 Jan 2024 09:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QSyIx2XL" Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (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 191ED39FFC for ; Mon, 22 Jan 2024 09:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705914776; cv=none; b=BRAcYi3gEaQRxdP4Qn3MegrB3HnE0ri2kQ5oq/zWPY9IdC63AID6x7xYqm/ldmMJrFNY1KNaTcNNoEfrlqoQ54JXbX2D+gJNvw2UE19n3EVPwj93VpcCKcmKq7RRhG6/Q657seroQgsnHm3X/EuvJWIcjGSB0qeO44uvb28OCSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705914776; c=relaxed/simple; bh=ASNAVMifMJd8QWZCGmHV1XRCtmfYXVarhOOObTd7G9Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gfI0ADomWHbAmCAJ5VixT3vix5p63Gjovw9oqkczIxGGLV9sq54dQclyhwAh2ATlvLRLR2QLhlLCbQZXNdT8j61QNUqzQ6kca3eRCQfP8vjbvygXx1ezzT2iHUCq3djLYNI8NEn7VGjpwe+CsFieLM9u8k15SMhRkQUQX++aO2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QSyIx2XL; arc=none smtp.client-ip=209.85.221.73 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=flex--ardb.bounces.google.com Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-33920fc3a71so1163299f8f.0 for ; Mon, 22 Jan 2024 01:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705914772; x=1706519572; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IfnnJzbo8UZ3onwnncaopOvG+BfrFgnNq0Hm48mm5EQ=; b=QSyIx2XLO3Ukws5iNR8IEj25V24mlpKUdoiYh5du7xe8WewTjRBtKFs/g6uYarQKzO VRoGNrke37rbCP0KyTL0di9N6puNLhMH788rivA4R5WWiXC7zYgypUjtq4gWqExt6m3i 3v6ekKoT+VWzEQgDq8zsV/wks/T2Fs7dpZqR846ASleYjmvXU/b+VPGw3KDbHHfX4xci a1BSuIqRh4W/B3FmbYcZW+A2YngkM0Q3HbrSe/XOMYHwudy/F26h98ck4mwXjdp94iDk faKpEjNQNq6SICdtf2kHy4LSi0pRdZhNBzJoJzq8eU08Cp2EeR9KM1MuIuCMe6ihRthK KKTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705914772; x=1706519572; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IfnnJzbo8UZ3onwnncaopOvG+BfrFgnNq0Hm48mm5EQ=; b=XuXkUuueDauZNBTdk0mnL+3r1D9tChIb2KgwL/lYcqDV8ec38vzXL73MPewGVVD0qk y4GKLFyYb5sPGF85MBcEel4zT4ZyhTwoYYXTlrs8DfnqLjqNGnnZRPa2oAtmfp8XSRXd xpuhu8BOtnFvt8umvxtOVTeqZam2qPjDO8C8N0ezQ3Ldwaww8uHO0Rzzgs8Mr4h+KBxs xGbZl0pp/1cK7SLTTtUQl8545g3mNKBADx08pLSJoe0obdo3/DemmSERbL9wR2nZIkkc uPWTeUsTWXIFvi7l84xWUgq47+hLKPzftSAKTOzru2qVmbPE8rXsuzC2/kXOOnS7xZzE KmXw== X-Gm-Message-State: AOJu0YxTUcjO6XO0UblBy/06nlxT/w0slEi/fTphzcqnVOZDH7PhQwck QsUOrraMHpXqZySyojqOCKkd0sSO/rS0KtR8gDjHrgvkqdffk8dmJnBh1VMiPofTzWqvN3pMe7l rXkxELqQkN9y9smBIRuPI6TcofTKbbbPSaH+v7wfWc1AY/6n6kYZacWy7SvQwU87brydAnCHe/h H6jC/9nyrJm0AdBbV86eh2q3UqckR+Fw== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:adf:edd1:0:b0:337:c61c:8543 with SMTP id v17-20020adfedd1000000b00337c61c8543mr14303wro.12.1705914772059; Mon, 22 Jan 2024 01:12:52 -0800 (PST) Date: Mon, 22 Jan 2024 10:08:56 +0100 In-Reply-To: <20240122090851.851120-7-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240122090851.851120-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=13097; i=ardb@kernel.org; h=from:subject; bh=/1VPj9HH1Zq9gl0WszFeYn5sVhTk4UiVd+cWeq9d1/A=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXWdwYrHX8M+PtC4ZFul4688vfaifPGEn1IXK7av/X32r Iq92bbajlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjCRNa8Y/hdaHkgpeGsWoSRr Zu72bmYma+pD83SVn1I+C94/eH1v0iNGhtv1Tr8mR6932nnVNPTRzSipkOU6/9kOxtvdTl8x/WL ddU4A X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240122090851.851120-11-ardb+git@google.com> Subject: [RFC PATCH 4/5] x86/head64: Replace pointer fixups with PIE codegen From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Martin KaFai Lau , Nathan Chancellor , Nick Desaulniers , Justin Stitt , linux-arch@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788781380521114865 X-GMAIL-MSGID: 1788781380521114865 From: Ard Biesheuvel Some of the C code in head64.c may be called from a different virtual address than it was linked at. Currently, we deal with this by using ordinary, position dependent codegen, and fixing up all symbol references on the fly. This is fragile and tricky to maintain. It is also unnecessary: we can use position independent codegen (with hidden visibility) to ensure that all compiler generated symbol references are RIP-relative, removing the need for fixups entirely. It does mean we need explicit references to kernel virtual addresses to be generated by hand, so generate those using a movabs instruction in inline asm in the handful places where we actually need this. While at it, move these routines to .inittext where they belong. Signed-off-by: Ard Biesheuvel --- arch/x86/Makefile | 11 ++ arch/x86/boot/compressed/Makefile | 2 +- arch/x86/include/asm/init.h | 2 - arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/Makefile | 4 + arch/x86/kernel/head64.c | 117 +++++++------------- 6 files changed, 60 insertions(+), 78 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 1a068de12a56..bed0850d91b0 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -168,6 +168,17 @@ else KBUILD_CFLAGS += -mcmodel=kernel KBUILD_RUSTFLAGS += -Cno-redzone=y KBUILD_RUSTFLAGS += -Ccode-model=kernel + + PIE_CFLAGS := -fpie -mcmodel=small \ + -include $(srctree)/include/linux/hidden.h + + ifeq ($(CONFIG_STACKPROTECTOR),y) + ifeq ($(CONFIG_SMP),y) + PIE_CFLAGS += -mstack-protector-guard-reg=gs + endif + endif + + export PIE_CFLAGS endif # diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index f19c038409aa..bccee07eae60 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -84,7 +84,7 @@ LDFLAGS_vmlinux += -T hostprogs := mkpiggy HOST_EXTRACFLAGS += -I$(srctree)/tools/include -sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' +sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' quiet_cmd_voffset = VOFFSET $@ cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@ diff --git a/arch/x86/include/asm/init.h b/arch/x86/include/asm/init.h index cc9ccf61b6bd..5f1d3c421f68 100644 --- a/arch/x86/include/asm/init.h +++ b/arch/x86/include/asm/init.h @@ -2,8 +2,6 @@ #ifndef _ASM_X86_INIT_H #define _ASM_X86_INIT_H -#define __head __section(".head.text") - struct x86_mapping_info { void *(*alloc_pgt_page)(void *); /* allocate buf for page table */ void *context; /* context for alloc_pgt_page */ diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h index 5c83729c8e71..dc657b1d7e14 100644 --- a/arch/x86/include/asm/setup.h +++ b/arch/x86/include/asm/setup.h @@ -48,7 +48,7 @@ extern unsigned long saved_video_mode; extern void reserve_standard_io_resources(void); extern void i386_reserve_resources(void); extern unsigned long __startup_64(unsigned long physaddr, struct boot_params *bp); -extern void startup_64_setup_env(unsigned long physbase); +extern void startup_64_setup_env(void); extern void early_setup_idt(void); extern void __init do_early_exception(struct pt_regs *regs, int trapnr); diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 0000325ab98f..65194ca79b5c 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -21,6 +21,10 @@ CFLAGS_REMOVE_sev.o = -pg CFLAGS_REMOVE_rethook.o = -pg endif +# head64.c contains C code that may execute from a different virtual address +# than it was linked at, so we always build it using PIE codegen +CFLAGS_head64.o += $(PIE_CFLAGS) + KASAN_SANITIZE_head$(BITS).o := n KASAN_SANITIZE_dumpstack.o := n KASAN_SANITIZE_dumpstack_$(BITS).o := n diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index dc0956067944..21f6c2a7061b 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -85,23 +85,8 @@ static struct desc_ptr startup_gdt_descr __initdata = { .address = 0, }; -static void __head *fixup_pointer(void *ptr, unsigned long physaddr) -{ - return ptr - (void *)_text + (void *)physaddr; -} - -static unsigned long __head *fixup_long(void *ptr, unsigned long physaddr) -{ - return fixup_pointer(ptr, physaddr); -} - #ifdef CONFIG_X86_5LEVEL -static unsigned int __head *fixup_int(void *ptr, unsigned long physaddr) -{ - return fixup_pointer(ptr, physaddr); -} - -static bool __head check_la57_support(unsigned long physaddr) +static bool __init check_la57_support(void) { /* * 5-level paging is detected and enabled at kernel decompression @@ -110,23 +95,28 @@ static bool __head check_la57_support(unsigned long physaddr) if (!(native_read_cr4() & X86_CR4_LA57)) return false; - *fixup_int(&__pgtable_l5_enabled, physaddr) = 1; - *fixup_int(&pgdir_shift, physaddr) = 48; - *fixup_int(&ptrs_per_p4d, physaddr) = 512; - *fixup_long(&page_offset_base, physaddr) = __PAGE_OFFSET_BASE_L5; - *fixup_long(&vmalloc_base, physaddr) = __VMALLOC_BASE_L5; - *fixup_long(&vmemmap_base, physaddr) = __VMEMMAP_BASE_L5; + __pgtable_l5_enabled = 1; + pgdir_shift = 48; + ptrs_per_p4d = 512; + page_offset_base = __PAGE_OFFSET_BASE_L5; + vmalloc_base = __VMALLOC_BASE_L5; + vmemmap_base = __VMEMMAP_BASE_L5; return true; } #else -static bool __head check_la57_support(unsigned long physaddr) +static bool __init check_la57_support(void) { return false; } #endif -static unsigned long __head sme_postprocess_startup(struct boot_params *bp, pmdval_t *pmd) +#define __va_symbol(sym) ({ \ + unsigned long __v; \ + asm("movabsq $" __stringify(sym) ", %0":"=r"(__v)); \ + __v; }) + +static unsigned long __init sme_postprocess_startup(struct boot_params *bp, pmdval_t *pmd) { unsigned long vaddr, vaddr_end; int i; @@ -141,8 +131,8 @@ static unsigned long __head sme_postprocess_startup(struct boot_params *bp, pmdv * attribute. */ if (sme_get_me_mask()) { - vaddr = (unsigned long)__start_bss_decrypted; - vaddr_end = (unsigned long)__end_bss_decrypted; + vaddr = __va_symbol(__start_bss_decrypted); + vaddr_end = __va_symbol(__end_bss_decrypted); for (; vaddr < vaddr_end; vaddr += PMD_SIZE) { /* @@ -169,13 +159,7 @@ static unsigned long __head sme_postprocess_startup(struct boot_params *bp, pmdv return sme_get_me_mask(); } -/* Code in __startup_64() can be relocated during execution, but the compiler - * doesn't have to generate PC-relative relocations when accessing globals from - * that function. Clang actually does not generate them, which leads to - * boot-time crashes. To work around this problem, every global pointer must - * be adjusted using fixup_pointer(). - */ -unsigned long __head __startup_64(unsigned long physaddr, +unsigned long __init __startup_64(unsigned long physaddr, struct boot_params *bp) { unsigned long load_delta, *p; @@ -184,12 +168,10 @@ unsigned long __head __startup_64(unsigned long physaddr, p4dval_t *p4d; pudval_t *pud; pmdval_t *pmd, pmd_entry; - pteval_t *mask_ptr; bool la57; int i; - unsigned int *next_pgt_ptr; - la57 = check_la57_support(physaddr); + la57 = check_la57_support(); /* Is the address too large? */ if (physaddr >> MAX_PHYSMEM_BITS) @@ -199,7 +181,7 @@ unsigned long __head __startup_64(unsigned long physaddr, * Compute the delta between the address I am compiled to run at * and the address I am actually running at. */ - load_delta = physaddr - (unsigned long)(_text - __START_KERNEL_map); + load_delta = physaddr - (__va_symbol(_text) - __START_KERNEL_map); /* Is the address not 2M aligned? */ if (load_delta & ~PMD_MASK) @@ -210,26 +192,22 @@ unsigned long __head __startup_64(unsigned long physaddr, /* Fixup the physical addresses in the page table */ - pgd = fixup_pointer(early_top_pgt, physaddr); + pgd = (pgdval_t *)early_top_pgt; p = pgd + pgd_index(__START_KERNEL_map); if (la57) *p = (unsigned long)level4_kernel_pgt; else *p = (unsigned long)level3_kernel_pgt; - *p += _PAGE_TABLE_NOENC - __START_KERNEL_map + load_delta; + *p += _PAGE_TABLE_NOENC + sme_get_me_mask(); - if (la57) { - p4d = fixup_pointer(level4_kernel_pgt, physaddr); - p4d[511] += load_delta; - } + if (la57) + level4_kernel_pgt[511].p4d += load_delta; - pud = fixup_pointer(level3_kernel_pgt, physaddr); - pud[510] += load_delta; - pud[511] += load_delta; + level3_kernel_pgt[510].pud += load_delta; + level3_kernel_pgt[511].pud += load_delta; - pmd = fixup_pointer(level2_fixmap_pgt, physaddr); for (i = FIXMAP_PMD_TOP; i > FIXMAP_PMD_TOP - FIXMAP_PMD_NUM; i--) - pmd[i] += load_delta; + level2_fixmap_pgt[i].pmd += load_delta; /* * Set up the identity mapping for the switchover. These @@ -238,15 +216,13 @@ unsigned long __head __startup_64(unsigned long physaddr, * it avoids problems around wraparound. */ - next_pgt_ptr = fixup_pointer(&next_early_pgt, physaddr); - pud = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr); - pmd = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr); + pud = (pudval_t *)early_dynamic_pgts[next_early_pgt++]; + pmd = (pmdval_t *)early_dynamic_pgts[next_early_pgt++]; pgtable_flags = _KERNPG_TABLE_NOENC + sme_get_me_mask(); if (la57) { - p4d = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], - physaddr); + p4d = (p4dval_t *)early_dynamic_pgts[next_early_pgt++]; i = (physaddr >> PGDIR_SHIFT) % PTRS_PER_PGD; pgd[i + 0] = (pgdval_t)p4d + pgtable_flags; @@ -267,8 +243,7 @@ unsigned long __head __startup_64(unsigned long physaddr, pmd_entry = __PAGE_KERNEL_LARGE_EXEC & ~_PAGE_GLOBAL; /* Filter out unsupported __PAGE_KERNEL_* bits: */ - mask_ptr = fixup_pointer(&__supported_pte_mask, physaddr); - pmd_entry &= *mask_ptr; + pmd_entry &= __supported_pte_mask; pmd_entry += sme_get_me_mask(); pmd_entry += physaddr; @@ -294,14 +269,14 @@ unsigned long __head __startup_64(unsigned long physaddr, * error, causing the BIOS to halt the system. */ - pmd = fixup_pointer(level2_kernel_pgt, physaddr); + pmd = (pmdval_t *)level2_kernel_pgt; /* invalidate pages before the kernel image */ - for (i = 0; i < pmd_index((unsigned long)_text); i++) + for (i = 0; i < pmd_index(__va_symbol(_text)); i++) pmd[i] &= ~_PAGE_PRESENT; /* fixup pages that are part of the kernel image */ - for (; i <= pmd_index((unsigned long)_end); i++) + for (; i <= pmd_index(__va_symbol(_end)); i++) if (pmd[i] & _PAGE_PRESENT) pmd[i] += load_delta; @@ -313,7 +288,7 @@ unsigned long __head __startup_64(unsigned long physaddr, * Fixup phys_base - remove the memory encryption mask to obtain * the true physical address. */ - *fixup_long(&phys_base, physaddr) += load_delta - sme_get_me_mask(); + phys_base += load_delta - sme_get_me_mask(); return sme_postprocess_startup(bp, pmd); } @@ -587,22 +562,16 @@ static void set_bringup_idt_handler(gate_desc *idt, int n, void *handler) } /* This runs while still in the direct mapping */ -static void __head startup_64_load_idt(unsigned long physbase) +static void startup_64_load_idt(void) { - struct desc_ptr *desc = fixup_pointer(&bringup_idt_descr, physbase); - gate_desc *idt = fixup_pointer(bringup_idt_table, physbase); - - - if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { - void *handler; + gate_desc *idt = bringup_idt_table; + if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) /* VMM Communication Exception */ - handler = fixup_pointer(vc_no_ghcb, physbase); - set_bringup_idt_handler(idt, X86_TRAP_VC, handler); - } + set_bringup_idt_handler(idt, X86_TRAP_VC, vc_no_ghcb); - desc->address = (unsigned long)idt; - native_load_idt(desc); + bringup_idt_descr.address = (unsigned long)idt; + native_load_idt(&bringup_idt_descr); } /* This is used when running on kernel addresses */ @@ -621,10 +590,10 @@ void early_setup_idt(void) /* * Setup boot CPU state needed before kernel switches to virtual addresses. */ -void __head startup_64_setup_env(unsigned long physbase) +void __init startup_64_setup_env(void) { /* Load GDT */ - startup_gdt_descr.address = (unsigned long)fixup_pointer(startup_gdt, physbase); + startup_gdt_descr.address = (unsigned long)startup_gdt; native_load_gdt(&startup_gdt_descr); /* New GDT is live - reload data segment registers */ @@ -632,5 +601,5 @@ void __head startup_64_setup_env(unsigned long physbase) "movl %%eax, %%ss\n" "movl %%eax, %%es\n" : : "a"(__KERNEL_DS) : "memory"); - startup_64_load_idt(physbase); + startup_64_load_idt(); } From patchwork Mon Jan 22 09:08:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 189986 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2453351dyb; Mon, 22 Jan 2024 01:14:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGtL1yO3LHKvwnD0HFmY9wYkphuDgW9e9h5pE+l5xmB8vnE8i3PCSy36TOyWtftwo2rpy3 X-Received: by 2002:a05:6214:c2a:b0:685:3e78:8723 with SMTP id a10-20020a0562140c2a00b006853e788723mr1463435qvd.28.1705914856975; Mon, 22 Jan 2024 01:14:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705914856; cv=pass; d=google.com; s=arc-20160816; b=a0PRfd7fyT3xluRHlDkAJ4YY19suA2Va+bSooEipwuFCaIYUAG6pVQcHi/j0LJgKLg ES/HvxH21sKU7QLErvcw3RkPRISxLg2R0AFT7mQLSRuuTcANATtpfuBGbZdre3fNU+Nd fwx+yukkbsUTcgQDS6w5SL9+AV+xAlnfKWjLiiAT3ko75zbR09U1NRWp5gtG23NmxA70 /sc0NURWC/fh2U4pKtTN7chxsKXCZoG+HpxnNJVZ679vPBaDDQBdtkHe4pfq9MHFkG+b /s70PR0nRr1SdDDjqz+gIXkaE+ifa+7ZAQzx1Crq/oFSWVs4XEVdf8dr1c5rY4L9sEbb 1t5A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=V3ieii7F07e2BhjymXZdDcuN6ywdVvzt+lwy6/7RWUY=; fh=48HUvOMbKpeHraf1klkRburnyvYvg0IkDo40jTOEaFs=; b=iJQiSpIroUYlGL3pg74bo3c8eUEn0cWc+8WxT9UjEdYRfbDrxa8i3YsGozGS7J6xH1 ppn21oFR0f+T781iUsATw6jIrvZYXCiWMhEtjL3+k5fV8aq13lRdF7HVOEyf4qlQuoh1 a7ddl1IDGgzyD8jKtrRo4pw6JmtIe8OPns1CZeFUpQaBcNWKL8JlusMl2Un/B/jAPt4S 2GKMin4JQDbZPGrDV2J5m4GFb7E11AonNDR0HS1TOe2YfiOPR9UPUx2uRa7xBIkTSEWI afSTAntcGQTEEDfgqolwLTiPgqwcL6cwIcfdhVffGik2vBZpcKp+muYOgtMys9TDmR99 s+Mg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GYrGHRpr; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-32603-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32603-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 x26-20020a0cb21a000000b0067a90d3023esi5383987qvd.279.2024.01.22.01.14.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 01:14:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32603-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=GYrGHRpr; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-32603-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32603-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 B36E41C241D7 for ; Mon, 22 Jan 2024 09:14:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7CD7C3A264; Mon, 22 Jan 2024 09:13:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GYrGHRpr" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 AB1763A1AF for ; Mon, 22 Jan 2024 09:12:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705914777; cv=none; b=HjPne+aV0GbHSrWv8cyFJKMBBZiCg7kZKb+aGcvh6LC+xZ4Wv4Df3qN46TD7EG3IUvjpbkRDpLmWPZMYE4BppSA4bPRzF29wOAM7EcH9nX0NytzSTd4wfzdOtxuo+FkayA9pCK8Yu7crE5fftnXpAuu8oux9W6j8QnZOqlnQ9VA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705914777; c=relaxed/simple; bh=WtGP1AHer5Q1wc5J6xuAlLFLTWrN4iBoK96MPonlw1U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WMHI7VHDS92cLdTf4VJaX4rAPRPduN3ZpbXjbGXK33fKdudM1bTdL2zt3P7EWlU8zxwPjouQVcHXj3PTlK4tVjDzwmesNBCpb3VvxDL97WAXKYykH5TdMnqmZOMKrlFetHn/1wY3fDxtFwvfapIU/wnlFatZUlwlIZcn/5nein8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GYrGHRpr; arc=none smtp.client-ip=209.85.219.201 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=flex--ardb.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc24de01bd9so4937125276.1 for ; Mon, 22 Jan 2024 01:12:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705914774; x=1706519574; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=V3ieii7F07e2BhjymXZdDcuN6ywdVvzt+lwy6/7RWUY=; b=GYrGHRpru70Fhxxy4VqdIM5MQbC1HdF20WX5HCHqnCI/tUIqzbAd4Khyy2U9uhhu1b WVJHpV8fIoPsEA1nEZVl2tkeNFkCtyxWEeRDryV74jEBnITYAr1eH9YnNuRSS59S43zk sZ5ePivZYEhvRtzrElRqCIoVT17mMZOLEHB84l8+Y/xtUNIZMKrW1OIbB53rEvxe3nhw CiP2iVenVt042QIZYIU0Q4IjVde+a5ceoDhslP+AxIbZJZssR3tf9Saat/z3hv9fX0Mc I9JVIeAl9lhm5X0jLJsrVtoxhSWRZQuJ86e8ba1LVlFrcauhTtPOcQI6LlETLea1kHjC 0idw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705914774; x=1706519574; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V3ieii7F07e2BhjymXZdDcuN6ywdVvzt+lwy6/7RWUY=; b=vDQaNrhldq3DTX/4BziVYiL3c/d+/wloRZluj0cCuXEtXtiP+RmRrNew2OGx60Mt0q lyLtq2g2DGENo60hOOtVe9mb2eN0NdQ73sc1SArHflm3bDIqx1j/L/o6XMEDyGnNxfRF lfb5OVBgrLWVzouSBmdLVsRFitjLUy9TvN7SAk7l00vG5UpGvQw52/NUXdsZpcEdZz8P nMT3YR60epqy4Wl8LozsG83wTEgCKsR+WQOELiLwK1GLanHPkzUPui3Xu+encqF4dU2A Nl/xwyopcE9/CQTy5xzzZ7L3hxwOuS3FfQJKfmBGWNgfIa6FmFO06kgsaX10r+w0kavm 70nQ== X-Gm-Message-State: AOJu0YwqfwqOxDDJPbRMfpxiNIzrjMKGp3JoCk1ZXq5SMCZEMLRUYQhp Xbl9kbz6ALvgsOp0D79f7ZF/tS+XiNEObkYfNODphIzwx2BCuxcH7C0itYL7rHJ/4MMkcCDYPRJ BpeCF5QEjjFxtJRWfjY+JXJC9o1vksynUXu55VXLwmXTL3kiPqa26YVOJUg3tQVqUiH0I9xji6Q eFAQ4Y7583cz7BkeNrYXqEC//GRrCZTw== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:1005:b0:dc2:5525:f6b with SMTP id w5-20020a056902100500b00dc255250f6bmr1879931ybt.7.1705914774527; Mon, 22 Jan 2024 01:12:54 -0800 (PST) Date: Mon, 22 Jan 2024 10:08:57 +0100 In-Reply-To: <20240122090851.851120-7-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240122090851.851120-7-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4335; i=ardb@kernel.org; h=from:subject; bh=NM5aMdSXYlJ+boACvwGHARd4V6ELPnCOafub2dfrC3k=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXWdwcq/f7QuR0w79JI76/onzQcqrKlfdTWq06uW7lKdI 7BeiHlnRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjIViZGhmuyC5eIZNR1xF4U +3hyvreGQ1XbpJCYhxeT1FJqs3/c+c3I8P/dL1X2K5ffWd5sXvTUkT/RfkWV3oyZaw7yf/GWsxF 4zwgA X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240122090851.851120-12-ardb+git@google.com> Subject: [RFC PATCH 5/5] x86: Build the core kernel with position independent codegen From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Martin KaFai Lau , Nathan Chancellor , Nick Desaulniers , Justin Stitt , linux-arch@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788781376563681307 X-GMAIL-MSGID: 1788781376563681307 From: Ard Biesheuvel Pass the -fpie flag to the compiler when building objects that are intended for the core kernel. This ensures that all implicit symbol references are emitted using RIP-relative relocations, allowing the code to be executed correctly even if it runs from a different virtual address than the address it was linked/loaded/relocated to run at. This is necessary to ensure that all C code that gets pulled in by the early startup code runs correctly without the need for unpalatable hacks in the code to force RIP-relative references. Signed-off-by: Ard Biesheuvel --- arch/x86/Makefile | 7 +++++-- arch/x86/entry/vdso/Makefile | 2 +- arch/x86/kernel/Makefile | 4 ---- arch/x86/realmode/rm/Makefile | 1 + include/asm-generic/vmlinux.lds.h | 2 ++ 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index bed0850d91b0..0382a9534099 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -165,11 +165,13 @@ else KBUILD_RUSTFLAGS += $(rustflags-y) KBUILD_CFLAGS += -mno-red-zone - KBUILD_CFLAGS += -mcmodel=kernel + KBUILD_CFLAGS_MODULE += -mcmodel=kernel KBUILD_RUSTFLAGS += -Cno-redzone=y - KBUILD_RUSTFLAGS += -Ccode-model=kernel + KBUILD_RUSTFLAGS_KERNEL += -Ccode-model=small + KBUILD_RUSTFLAGS_MODULE += -Ccode-model=kernel PIE_CFLAGS := -fpie -mcmodel=small \ + $(call cc-option,-Wa$(comma)-mrelax-relocations=no) \ -include $(srctree)/include/linux/hidden.h ifeq ($(CONFIG_STACKPROTECTOR),y) @@ -178,6 +180,7 @@ else endif endif + KBUILD_CFLAGS_KERNEL += $(PIE_CFLAGS) export PIE_CFLAGS endif diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index b1b8dd1608f7..e2c79d4c1417 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -149,7 +149,7 @@ $(obj)/vdso32.so.dbg: KBUILD_AFLAGS = $(KBUILD_AFLAGS_32) $(obj)/vdso32.so.dbg: asflags-$(CONFIG_X86_64) += -m32 KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS)) -KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32)) +KBUILD_CFLAGS_32 := $(filter-out -mcmodel=small,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(RANDSTRUCT_CFLAGS),$(KBUILD_CFLAGS_32)) diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 65194ca79b5c..0000325ab98f 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -21,10 +21,6 @@ CFLAGS_REMOVE_sev.o = -pg CFLAGS_REMOVE_rethook.o = -pg endif -# head64.c contains C code that may execute from a different virtual address -# than it was linked at, so we always build it using PIE codegen -CFLAGS_head64.o += $(PIE_CFLAGS) - KASAN_SANITIZE_head$(BITS).o := n KASAN_SANITIZE_dumpstack.o := n KASAN_SANITIZE_dumpstack_$(BITS).o := n diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile index f614009d3e4e..fdb8e780f903 100644 --- a/arch/x86/realmode/rm/Makefile +++ b/arch/x86/realmode/rm/Makefile @@ -76,5 +76,6 @@ KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \ -I$(srctree)/arch/x86/boot KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables +KBUILD_CFLAGS_KERNEL := $(filter-out $(PIE_CFLAGS),$(KBUILD_CFLAGS_KERNEL)) GCOV_PROFILE := n UBSAN_SANITIZE := n diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index ef45331fb043..9518b87207e8 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -355,6 +355,7 @@ *(.data..decrypted) \ *(.ref.data) \ *(.data..shared_aligned) /* percpu related */ \ + *(.data.rel .data.rel.*) \ MEM_KEEP(init.data*) \ *(.data.unlikely) \ __start_once = .; \ @@ -477,6 +478,7 @@ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ __start_rodata = .; \ *(.rodata) *(.rodata.*) \ + *(.data.rel.ro*) \ SCHED_DATA \ RO_AFTER_INIT_DATA /* Read only after init */ \ . = ALIGN(8); \